0

this might be weird but what I am trying to do is this:

I have a node.js script which does some stuff, like reading some data from a file, doing some stuff (converts it to some format) and then writes processed data to another one while sends the same data to an api with node-fetch.

What I want to do is,

  1. I am building a vue.js web app and want to run this web app locally (maybe I will put on a server later). Simply, when the user presses a button, it will run the above-mentioned node.js file.

I am not sure, maybe it is easy but could not do it and could not find an exact solution from googling.

thanks in advance

I tried to "import" the node.js app but it gave error as there is no default export statement... there is Q&A Running a node.js file from website. as far as I understand this is not the exact thing I am looking... In this answer (I loved it), there is a server.js which calls a function from another node.js file...

In my case, I have a vue.js web app, which will execute the pre-defined node.js file...

m-alptekin
  • 11
  • 5

1 Answers1

0

Node.js is not a browser plugin. JavaScript that depends on Node.js cannot run inside the browser.

Browsers provide no APIs for running arbitrary executables (such as Node.js) on the user's computer.


Your options include:

  • Rewrite the Node.js code to be browser compatible (e.g. replace any code that reads file from the file system with code that reads file from a <input type=file>).
  • Write a desktop application with Electron or similar instead of a web app
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks Quentin... As you said I tried several node.js libraries like file system, child_process etc and they are not browser compatible.. is it somehow possible to serve a backend with express.js and make vue.js front end talk with this server.js file and deal the node.js stuff with this server.js file? My second comment and question is before creating a web app, I tried to build a desktop app with vue but vue+electron has some limitations I guess... The best template I found uses typescript which is not much suitable for me. Do you have any suggestion for vue and electron.? – m-alptekin Feb 23 '23 at 11:49