How to define custom nodemon configuration in nodemonConfig in package.json?

11.8k views Asked by At

I tried implementing custom nodemon configuration in package.json as shown below:

"nodemonConfig": {
    "watch": ["server", "bin/www"],
    "ext": "ts",
    "ignore": ["*.test.ts"],
    "delay": "3000",
    "execMap": {
      "ts": "ts-node"
    }
  }

Yet, it didn't work. Nodemon doesn't restart when ./bin/www is edited, nor does ignoring the files that restart the server works.

Can anyone suggest me the correct nodemonConfig?

3

There are 3 answers

0
Soumitya Chauhan On

package.json

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js",
    "dev": "nodemon index.js"
  },

Terminal

npm run dev
0
Subfuzion On

You were close. First piece of advice is when you're having issues, add the verbose flag.

Second, although you correctly configured nodemon options and mappings, you still need to tell it what to execute (bin/www).

Your package.json should look like this:

{
  "scripts": {
    "dev": "nodemon bin/www"
  },
  "nodemonConfig": {
    "verbose": true,
    "watch": ["server", "bin/www"],
    "ext": "ts",
    "ignore": ["*.test.ts"],
    "delay": "3000",
    "execMap": {
      "ts": "ts-node"
    }
  }
}

Note: execMap already defaults to ts-node, see defaults.js.

1
William Vbl On

I think these settings only work when npm is starting nodemon, something like

// package.json
"scripts": {
  "start:dev": "DEBUG=app:* nodemon app.js"
}

then use

$> npm run start:dev