简体   繁体   中英

How do I refresh the server in node.js

I have an application where I am sending a JSON file to the server. The JSON file can change so I want it to reload the server everytime it changes. But when I put location.reload() it gives me an error that location is not defined.
What Should I use instead of location.reload()

A solution that I have done before is to use nodemon (instead of node) to run your node application. Nodemon is designed to restart the node application when it detects changes in the file system. So if you have a node application that writes a JSON file to disk, in the same folder as the node application, then it will restart when the file is changed.

You can use something like "forever".

npm install forever

Then change the package json

"start": "forever start index.js"

then whenever you want to force the restart, you just call

process.exit(1);

this will try to force a restart on your server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM