ameni
ameni

Reputation: 393

start and stop node.js script automatically

Is there any solution to start and stop a node.js script without using command prompt on Windows machine? I mean by using a script to start and stop the node.js server (without the need to the command prompt)

Upvotes: 0

Views: 2708

Answers (2)

Pampattitude
Pampattitude

Reputation: 456

There is a simple problem with your query: how do you launch the script to stop your Node.js process without a prompt?

An option which will most likely fit your needs is to use pm2. PM2 is a process manager in which you can start, restart, stop, etc. Node.js processes.

You can start your script with pm2 start PATH_TO_SCRIPT -n IDENTIFICATION_NAME, then stop it with pm2 stop IDENTIFICATION_NAME or restart it with pm2 restart IDENTIFICATION_NAME.

If you want to simplify the process or have an icon to double-click on to manage your Node.js script, you could execute the above commands in a Batch script.


PM2 also has a Web service, Keymetrics, to manage processes remotely (via a Web interface).

Hope it helps!

Upvotes: 3

Rahul Kamboj
Rahul Kamboj

Reputation: 469

Try nodemon. it will give you the power to auto restart your server after the file change Done.

npm install -g nodemon

after installation just use nodemon instead of node to run your file.

Upvotes: 0

Related Questions