How to close a terminal window when executing a file using node.js without stopping the process?

When I run the file with node.js (by typing "node example.js", possibly an http server), then when I close the terminal window (Mac OS X Lion), the process stops and no longer responds. The same thing happens if I type "ctrl c" or "ctrl z". How to close the terminal without stopping the process, so my server continues to respond to requests.

+4
source share
1 answer

Use a combination of the nohup prefix command (to prevent the process from being killed when the terminal closes) and the & suffix (to start the process in the background so that it does not bind the terminal): nohup node example.js &

You should also look into forever or similar tools, which will also automatically restart the server if it works, and nodemon , which will automatically restart it when the code changes.

+13
source

All Articles