E
E
eugeenyjoy2021-01-04 10:16:05
Node.js
eugeenyjoy, 2021-01-04 10:16:05

How to execute node js script on request from browser?

You need to somehow get new data from the database, while not restarting the application from the console.
What happens:
- Take data from the database 1 time, when executing the script
- Take the page with ajax (stupid code)
- Using msql-loader I can console data from the database, but when changed in the database, they do not change in the browser, because the data is received at the time of the script execution, period, but re-execute the script, but I don’t think it’s possible at the request from the browser (this is the question)
What doesn’t work:
- without going to the console and without typing npm run build or node bd.js Execute the script on the server , for example bd.js on any request from the browser.
Ps I tried as in php just in ajax url indicated bd.js, and naturally instead of the result I got only the source code of the script

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-01-04
@eugeenyjoy

I tried it as in php, I just specified the url in Ajax
We tried it correctly, but the web server must be running on the server, which will send requests to the node (well, or it itself can be such a server), and the node already has the logic that returns the data. Google express.js for example.
without entering the console and without typing npm run build or node bd.js Execute a script on the server, for example bd.js, on any request from the browser
But this is impossible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question