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

添加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

 

posted @ 2018-12-22 10:44  两面一汤  阅读(796)  评论(0编辑  收藏  举报