Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running two node servers from a single shell command using a shell script

I have to run two node servers in different port, I want to write a simple shell script that will start both of the servers.

I wrote it like below:

node project/rest.js && node static-server.js

but when I run the commands at a time, it starts the first server and dont execute the second one.

And only the fist server listens for request, second static server doesn't start. And in the shell I do have a output from rest.js.

What I previously did to run tow servers, I run two commands in different shell.

Is there a way I can run both of the server with a single shell script?

Thanks in advance.

like image 958
arnold Avatar asked Jun 13 '13 11:06

arnold


People also ask

How do I run a shell script on multiple servers?

To run commands on multiple servers, add the servers to a hosts file as explained before. Then run pdsh as shown; the flag -w is used to specify the hosts file, and -R is used to specify the remote command module (available remote command modules include ssh, rsh, exec, the default is rsh).

How do I run multiple node servers?

use a reverse proxy like nginx, you don't need to handle this manually. Run both apps on two different prots. It can match a pattern in url, based on which redirect the request to corresponding app.


1 Answers

Your command does not work because you are trying to have two processes running in the same shell. Instead, you should 'spawn' the node processes into different processes. Try this command:

node project/rest.js & node static-server.js &
like image 153
verybadalloc Avatar answered Nov 03 '22 20:11

verybadalloc