Open multiple node.js servers with batch file
If you place a batch file in the directory where all these folders are (I guess its your nodejs directory), you can create a start.bat
file containing the commands:
start mongodb/bin/mongod
start node forum/proxy.js
start node forum/app.js
start node game/app.js
This will execute every command simultaneously, in a separate window.
Save this as a file with a .bat
extension and you are done
Old answer:
mongodb/bin/mongod
node forum/proxy.js
node forum/app.js
node game/app.js
Or if you want all the processes to run in a separate window:
start cmd /k mongodb/bin/mongod
start cmd /k node forum/proxy.js
start cmd /k node forum/app.js
start cmd /k node game/app.js
v3xx3d
Web Developer Extraordinaire at Level Interactive "Don't let your dreams be dreams." - Shia Labeouf
Updated on June 11, 2022Comments
-
v3xx3d almost 2 years
I'm using Windows. Currently every time I restart my server I have to run a bunch of commands to get my servers up and running and I'd like to consolidate them into a single batch script if possible.
Here's the process I currently have to run through:
open command prompt
cd /mongodb/bin
mongodopen another command prompt
cd /forum
node proxy.jsopen another command prompt
cd /forum
node app.jsopen ANOTHER command prompt
cd /game
node app.jsI feel like there is definitely a better way to do this but I can't seem to find an appropriate solution.
-
DDM over 9 yearsI applied the first-set. The problem - Second NodeJS execution (e.g. here for forum/app.js) did not begin until I terminated (ctrl+c) the first process in the Command window. Please suggest an approach where I can do the same thing in the same window
-
MarijnS95 over 9 years@DDM That is what the second piece of code does, although it doesn't look clean. I changed the answer to an asynchronous way, which has the same result as the second part.
-
zero_cool almost 5 yearsdid not work for me - how are you going to run proxies and servers and mongo from one process? you need to have a separate process for each command...
-
MarijnS95 almost 5 years@zero_cool What exactly are you trying to achieve? It turns out you can pass
/wait
to thestart
command, which'll wait for the process to exit before continuing the script. -
zero_cool almost 5 yearsI tried wait - but it won't work because you can't enter a command in a shell that's running a server for instance the command won't execute in the proper context - a simple example would be launching mongod and a node server with one command - you couldn't use wait for that - if you launched mongod - entering node ./server.js would be meaningless in the same shell
-
MarijnS95 almost 5 years@zero_cool Which is why I asked what you are trying to achieve; running one after the other makes zero sense when the node instance needs to connect to mongod. If you want to have two shells show up to be able to interact with the applications separately, try the
cmd /k
(or with/c
) example in the answer.