2

I am looking for a way to stop a node.js's server from a batch file. For eg: I have a batch file called start.bat in which I am starting node.js server like this node c:\test.js, so this will start server on port 8080, similarly I would like to stop that test.js server from another batch file called stop.bat. How can I do this?

I tried looking into many similar questions in SO, but all of them uses start and stop from the same .js file.

So is this possible? If yes, can anyone guide me?

2 Answers 2

1

you could use forever to start and stop the server: https://github.com/nodejitsu/forever

first install it globally:

npm install -g forever

run the server:

forever start test.js

stop the server:

forever stop test.js

of course you can also put this script in a .bat file :)

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, one quick help, whenever I try to run this command, node.exe opens a new window. Is it possible to hide it?
forever seems to have some incompatibility on windows, alternative approach: in start.bat "node test.js"; in stop.bat "taskkill /IM node.exe"
1

I was just playing around with the same functionality. I managed to start node without opening a cmd window by launching it with a .vbs

This a script I patched together that will start your server and then launch chrome on your localhost:

 Dim objWshShell, ls, lc
 set objWshShell = WScript.CreateObject("WScript.Shell")
 ls = objWshShell.Run("cmd /k cd C:\the\path\to\your\server && node myServer.js", 0, false)
 lc = objWshShell.Run("chrome localhost:8080", 1, false)
 set objWshShell = nothing

By passing a 0 in the first run command myServer.js will launch without a cmd window. I am sure that something link this could be adapted to give you the functionality your are looking for!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.