express+nodemon 修改后浏览器自动刷新

时间:2023-12-30 18:31:56

添加nodemon模块

cnpm install --save nodemon

根目录添加文件 nodemon.json

{
"restartable": "rs",
"ignore": [
".git",
".svn",
"node_modules/**/node_modules"
],
"verbose": true,
"execMap": {
"js": "node --harmony"
},
"watch": [ ],
"env": {
"NODE_ENV": "development"
},
"ext": "js json njk css js "
}

express 修改内容后自动更新(免重启)

entrance.js内容

const express = require("express"),
app = express(),
debug = require('debug')('my-application'); // debug模块 app.all("*", function (req, res, next){
res.send('fdssc')
}) app.set('port', process.env.PORT || 9000); // 设定监听端口
const server = app.listen(app.get('port'), function () {//启动监听
debug('Express server listening on port ' + server.address().port);
});

package.json添加

"scripts": {
"dev":"nodemon entrance.js"
}

执行启动 cnpm run dev