Wei Keat Wei Keat - 6 months ago 30
Linux Question

NodeJS is how can I run two server file from ubuntu?

Example like now if I run NodeJS on windows then I able to open 2 command prompt and run node server1.js and server2.js seperately but i am wondering how i can run this 2 server file on Linux ubuntu?

Because one is for websocket use and another one is for static web page use


How to create "a second command prompt"

What you are looking for is called a terminal multiplexer. There is a REALLY useful command called screen. As of ubuntu release jaunty it comes pre packaged. I highly recommend learning about it, because it can be used for so much more than just NodeJS.

Screen is a terminal multiplexer, which allows a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session (such as when using SSH).

Use it like this

  1. Type screen - This will create a "second window". Once you are in, you can type any commands you want, just like normal cli. For example, nodejs server1.js

  2. Type ctrl+a+d to exit the screen.

  3. Create a new screen by typing screen again.
  4. screen -ls to list screens and their individual ids.
  5. screen -x to re-attach to a recent screen.
  6. screen -r <id> to re-attach to a specific screen.
  7. kill -9 <id> to end a specific screen.