Skip to content Skip to sidebar Skip to footer

How To Run Multiple Js Servers

I'm developing a discord bot for discord at the moment, and to run the bot, I have a few different files. I've run into some problems along the way that all ended up having the sam

Solution 1:

You can use concurrently or parallel in order to make it cross platform

example with concurrently:

package.json
{
  "scripts": {
    "serve": "nodemon index.js",
    "logs": "nodemon logs.js",
    "start": "concurrently \"npm:serve\"\"npm:logs\""
  },
  "devDependencies": {
    "concurrently": "^5.0.0",
  }
}

Edit: you may want to take a look at the VSCode Compound tasks

Here's an example setup

Solution 2:

Welcome :-)

I think you mean bash file (.sh) instead of batch file. So, in the terminal, you can && commands to chain them together.

For example, you could chain them together like this:

nodemon ./appOne/index.js && nodemon ./appTwo/index.js && nodemon welcome and goodbye.js

and they will all execute at one time. Additionally, you could make a bash file somewhere on your computer that did exactly what I typed above :-)

Now if you wanted them to go to the background and you wanted to forget about them, you could put them in the background with one ampersand... like so:

nodemon index.js &

and it would disappear and you'd have your console back. It would also print out a process ID (PID) of what that node process is under, so you can find it and kill it later (via kill -9 processid)

Post a Comment for "How To Run Multiple Js Servers"