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?
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 :)
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!