【问题标题】:How to change nodemon default start file?如何更改 nodemon 默认启动文件?
【发布时间】:2018-06-18 18:57:23
【问题描述】:

我有一个网络应用程序。我想使用 nodemon 。要启动我的应用程序需要运行 'node ./bin/www',但 nodemon 默认运行另一个文件。而且我的网络应用程序不可用。

当我输入 cmd 时

nodemon

我明白了:

[nodemon] 1.14.10
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`

但我想将默认启动文件从 node app.js 更改为 node ./bin/www

我该怎么做?

package.json

{
  "name": "loc8r",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.18.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.15.5",
    "jade": "~1.11.0",
    "mongoose": "4.13.9",
    "morgan": "~1.9.0",
    "nodemon": "^1.14.9",
    "readline": "1.3.0",
    "request": "^2.83.0",
    "serve-favicon": "~2.4.5"
  },
  "main": "app.js",
  "devDependencies": {},
  "author": "",
  "license": "ISC",
  "description": ""
}

【问题讨论】:

    标签: nodemon


    【解决方案1】:

    nodemon 应该获取 "main": "file_to_be_executed.js", 中的任何文件,因此如果您要执行 www 文件,请将:"main": "app.js", 更改为:"main": "./bin/www",

    【讨论】:

    • 如果您使用 Express Js 作为框架,那么即使 bin/www 也会运行 app.js,并且它会包含在 www 文件的第一行,例如 var app = require('../app');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 2019-03-23
    • 2023-03-23
    相关资源
    最近更新 更多