使用批处理文件打开多个node.js服务器

v3x*_*x3d 5 windows automation batch-file node.js

我正在使用Windows.目前每次重新启动我的服务器时,我都必须运行一系列命令来启动和运行我的服务器,如果可能的话,我想将它们合并为一个批处理脚本.

这是我目前要经历的过程:

打开命令提示符
cd/mongodb/bin
mongod

打开另一个命令提示符
cd/forum
node proxy.js

打开另一个命令提示符
cd/forum
node app.js

打开另一个命令提示符
cd/game
node app.js

我觉得肯定有更好的方法可以做到这一点,但我似乎找不到合适的解决方案.

Mar*_*S95 8

如果将批处理文件放在所有这些文件夹所在的目录中(我猜它是你的nodejs目录),你可以创建一个start.bat包含命令的文件:

start mongodb/bin/mongod
start node forum/proxy.js
start node forum/app.js
start node game/app.js
Run Code Online (Sandbox Code Playgroud)

这将在一个单独的窗口中同时执行每个命令.将此保存为带.bat扩展名的文件,您就完成了

老答案:

mongodb/bin/mongod
node forum/proxy.js
node forum/app.js
node game/app.js
Run Code Online (Sandbox Code Playgroud)

或者,如果您希望所有进程在单独的窗口中运行:

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
Run Code Online (Sandbox Code Playgroud)