Introduce part1.

Nodemon is a tool that helps develop Node.js-based applications by automatically restarting node applications when changes to files in directories are detected

Nodemon does not require any additional changes to your code or methods of development. The Nodemon can directly replace the Node command.

For example :node index.js – > nodemon index.js

Installed part2.

Use instructions:

npm install -g nodemon

Example Install nodemon “nodemon –exec ts-node SRC /index.ts” in the global environment

Part3. The configuration

There are two configuration methods

Create nodemon. Json

in nodemon.json
{
  "verbose": true,
  "ignore": ["*.test.js", "fixtures/*"],
  "execMap": {
    "rb": "ruby",
    "pde": "processing --sketch={{pwd}} --run"
  }
}
Copy the code

or

in package.json { "name": "nodemon", "homepage": "http://nodemon.io", "..." : "... other standard package.json values", "nodemonConfig": { "ignore": ["test/*", "docs/*"], "delay": "2500" } }Copy the code

PS: You can even go to the root directory of Nodemon and find a file called defalut.js to directly change the global configuration.

Part4. Parameter Description

– h or -help:

View examples of help menu commands:

  • nodemon -h

–exec

Run non-JS programs

Instruction examples:

  • Nodemon –exec ts-node SRC /index.ts Uses the TS-node to run the index.ts in the SRC directory
  • /app.py run app.py from python in verbose mode notice that if you want to compile with arguments, you need to add “”, but if there are no arguments, you do not need” “.

–ignore

Some file/directory/file modes are ignored while hot updating

Instruction examples:

  • Nodemon –ignore lib/ Ignore lib internal file changes

–watch

Hot updates monitor more files, and if those monitored files are updated, your project is also hot updated

Command example: nodemon –watch index.js –watch./dist/ceshi.js

Directory structure:

in ceshi.js

console.log('in ceshi.js');
Copy the code

in index.js

console.log('in index.js');
Copy the code

At this point, if ceshi.js is changed, the console will output in index.js, but not in ceshi.js, because the entry files index.js and ceshi.js do not depend on each other, but they are being monitored.

-e

By default, Nodemon looks for extensions with files.js,.mjs,.coffee,.litcoffee, and.json. You can use the -e (or –ext) switch to specify your own list instruction example: nodemon-e JS, pug

Updates to PUG files now cause hot updates to projects