In the previous express framework in node, after each code modification, you need to re-npm start to see the effect of the change, which is very troublesome, so the nodemon module is introduced here to achieve the advantage of automatic update without restarting
1. Install nodemon globally
npm install -g nodemon
or install locally
npm install nodemon --save
2. Create a nodemon.json file in the project directory
{ "restartable": "rs", "ignore": [ ".git", ".svn", "node_modules/**/node_modules" ], "verbose": true, "execMap": { "js": "node --harmony" }, "watch": [ ], "env": { "NODE_ENV": "development" }, "ext": "js json" }restartable-set restart mode
ignore-set ignore file
verbose-set log output mode, true verbose mode
execMap-set the suffix name of running service and the corresponding command
{
"js": "node -harmony"
}
means use nodemon instead of node
watch- Monitor which files change, and automatically restart when changed
ext-monitor the specified suffix file name
3. Modify the app.js file
Remember to note the last line: module.exports = app;
var debug = require('debug')('my-application'); // debug模块 app.set('port', process.env.PORT || 3000); // set listening port // start listening var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); }); //module.exports = app;//This is the default configuration of 4.x, the app module is separated, just annotate it, and you can change it back when you go online
4. After the configuration is complete, run it
nodemon app.js