Node --- 01 nodemon depends on thermal overload

Do Vue JS for a long time, subconsciously rely on thermal overload, ctrl+s save!! The page automatically presents the latest status!! It's great!!

Lead to node JS, ctrl+s saves, and looks forward to waiting for the latest state. The result Hey, hey?? oh This is node JS, you need to enter a command

"node [startup file]" can be recompiled and started (disgusting face ~)

So I searched for a wave and found this thing - nodemon (automatic restart module)

nodemon is used to monitor node JS application and automatically restart the service, which is very suitable for use in the development environment.

Nodemon will monitor the files in the startup directory, and if there are any file changes, nodemon will automatically restart the node application.

nodemon does not need to make any changes to the code or development method. nodemon simply wraps your node application and monitors any changed files. nodemon is just a replacement package for node. It is only used to replace node on the command line when running the script.

To install nodemon, you need to enter the command "nodemon [startup file]".


1. Installation dependency

Global installation:

npm install -g nodemon

Local installation:

npm install nodemon --save-dev

After installation, you can check the version through nodemon -v to determine whether the installation is successful

2. Start nodemon

Enter the command line:



[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
Server running on URL

3. About CLI options

Enter the command line:

nodemon -h



  --config file ............ alternate nodemon.json config file to use // Standby nodemon JSON configuration file usage
  -e, --ext ................ extensions to look for, ie. js,jade,hbs. // Monitors files with the specified suffix
  -x, --exec app ........... execute script with "app", ie. -x "python -v". // Commands executed
  -w, --watch dir........... watch directory "dir" or files. use once for // Monitoring folder
                             each directory or file to watch.
  -i, --ignore ............. ignore specific files or directories. // Ignore specific files or directories
  -V, --verbose ............ show detail on what is causing restarts. // Displays the details that caused the restart
  -- <your args> ........... to tell nodemon stop slurping arguments. // Tell nodemon to stop the parameter

  Note: if the script is omitted, nodemon will try to read "main" from
  package.json and without a nodemon.json, nodemon will monitor .js, .mjs, .coffee,
  and .litcoffee by default.

  For advanced nodemon configuration use nodemon.json: nodemon --help config
  See also the sample:


  $ nodemon server.js
  $ nodemon -w ../foo server.js apparg1 apparg2
  $ nodemon --exec python
  $ nodemon --exec "make build" -e "styl hbs"
  $ nodemon app.js -- --config # pass config to app.js

At this time, I observed "-- config file"

Originally, in addition to modifying nodemon's configuration through commands, I can create another file as nodemon's configuration file

4. Configure nodemon JSON file

Create nodemon. In the following directory JSON file

  "watch": ["src"], // Listen for file changes in src directory
  "ext": "ts", // Monitors files with the specified suffix
  "ignore": ["src/**/*.spec.ts"], // Ignored file name suffix or folder
  "exec": "node" // Commands that are automatically executed when changes are monitored

Enter the command line:

nodemon --config nodemon

When you restart the service, you will find that the configuration of the output has changed:

[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
Server running on URL

5. Small expansion

Modify package JSON configuration:

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

Entering npm run server on the command line is equivalent to executing nodemon.


let express = require('express');
const app = express();
const port = process.env.PORT || 5000;

app.get("/", (req, res) => {
    res.send("Hello World!");

app.listen(port, () => {
    console.log(`Server running on URL${port}`);

Terminal input:

npm run server

The following errors may be reported:

Nodemon: unable to load the file C: \ users \ 19336 \ appdata \ roaming \ NPM \ nodemon PS1, because running scripts is prohibited on this system.

terms of settlement:

1. Open powerShell as Administrator

2. Enter set executionpolicy remotesigned

3. Just choose Y or A

Server successfully opened: npm run server






Keywords: node.js

Added by Coronet on Fri, 11 Feb 2022 20:17:17 +0200