zoukankan      html  css  js  c++  java
  • node.js+express框架 修改后自启【不需要再执行start】

    我们每次修改完后都需要重新启动下才能刷新,就很麻烦‘nodemon’解决了这个问题。

    • 这里直接进行全局安装
    npm install -g nodemon
    
    • 安装到本地
    npm install nodemon --save
    
    • 在项目目录下创建 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"
    }
    
    • 在app.js里添加代码
    const port = 8080 ;
    const debug = require('debug')('my-application'); // debug模块
    
    app.set('port', process.env.PORT || port); // 设定监听端口
    //启动监听
    var server = app.listen(app.get('port'), function() {
      debug('Express server listening on port ' + server.address().port);
    });
    
    • 以上步骤完成后启动项目
    打开cmd进入当前项目里有app.js
    输入‘nodemon app.js’即可启动 随意修改内容就会刷新。。。 
    
  • 相关阅读:
    NOIP2016 愤怒的小鸟
    LCIS code force 10D
    UVA 1398
    uva1382 Distant Galaxy
    洛谷-3930(我在洛谷上也写了题解)
    HDU-1505 City Game
    导弹拦截n logn的算法(单调性)洛谷1020
    POJ 1182 食物链
    POJ
    1202. 交换字符串中的元素
  • 原文地址:https://www.cnblogs.com/1748sb/p/13899275.html
Copyright © 2011-2022 走看看