How to restart multiple server files on npm script using nodemon when changing the files

6k views Asked by At

When I am changing the file on the folder I want to restart the two server files using nodemon in npm script

Here my npm script

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": 
    "nodemon app/api/server.js && nodemon app/backend/server.js"
 },
3

There are 3 answers

0
Sivabalan On BEST ANSWER

I finally done that by using concurrently plugin

And my npm start script will be

"start": "concurrently \"nodemon app/backend/server.js\" \"nodemon app/api/server.js\" "
0
Akram Saouri On

here's how your start script should look like in the package.json file:

"start": "nodemon app/api/server.js app/backend/server.js"
5
Sridhar On

You can use nodemon's configuration file nodemon.json for specifying additional settings. Place this file at the root of your application.

nodemon.json

{
  "restartable": "rs",
  "ignore": [
    ".git",
    "node_modules/**/node_modules"
  ],
  "verbose": true,
  "watch": [
    "app/api/server.js", //list of files, you want to watch for changes
    "app/backend/server.js" 

    // "app/api/", if you want to watch for all files in sub directory
  ],
  "ext": "js json"
}

Making those changes, your package.json should look like

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": 
    "nodemon app/api/server.js" // file list was added in nodemon.json
 },