【问题标题】:nodemon not working节点不工作
【发布时间】:2020-11-27 14:03:40
【问题描述】:

当我运行 nodemon 时,它显示

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

但是当我运行 npm start 时,一切正常。为什么 nodemon 不工作

我的 package.json

{
  "name": "sarthakmedia",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "cookie-parser": "~1.4.3",
    "cors": "^2.8.4",
    "debug": "~2.6.9",
    "express": "~4.16.0",
    "express-mysql-session": "^1.3.0",
    "express-session": "^1.15.6",
    "git": "^0.1.5",
    "http-errors": "~1.6.2",
    "jade": "~1.11.0",
    "morgan": "~1.9.0",
    "mysql": "*",
    "nodemon": "^1.17.4",
    "pug": "2.0.0-beta11"
  },
  "description": "practise",
  "main": "app.js",
  "devDependencies": {},
  "author": "Anita",
  "license": "ISC"
}

API 根本不会被调用。 nodemon 启动正常

【问题讨论】:

  • 在我看来 nodemon 工作正常。什么不工作?您可以在本地访问您的应用程序吗?还是不行?
  • 当我进行 api 调用时,它不会发送任何请求。使用 npm start 时请求在哪里工作正常
  • 你能分享你的 package.json 内容吗?或者至少是你的 npm 启动规则?
  • 为什么是 标签? (您可能是指 吗?)

标签: sql node.js express nodemon


【解决方案1】:

试试这个

  1. 第一步 在 package.json 文件中

“脚本”:{ “开始”:“节点应用程序”, "dev":"nodemon 应用程序" }

  1. 第二步 安装 nodemon 作为 devdependencies 使用代码 npm i -D nodemon

3)在 app.js 文件中

const express = require("express");
const app = express();

// routes
app.get("/",(req,res)=>{
    res.send("hello");
});

// server started
const port =process.env.PORT || 5000;
app.listen(port,()=>{
    console.log("server started at port 5000");
});

4)第四步

在命令行工具中使用 (npm run dev)

【讨论】:

    【解决方案2】:

    Nodemon 通过运行文件 ./app.js 启动。
    但是您的启动 npm 脚本(根据您的问题工作)运行不同的文件 ./bin/www/index.js

    我认为你应该告诉 nodemon 哪个文件是你的入口点。
    因此,您应该使用相同的值编辑 package.json 中的“main”条目,例如 ./bin/www。事实上,nodemon 在你的 package.json 中读取这个值是为了知道从哪个文件开始。

    【讨论】:

      【解决方案3】:

      当您位于应用根目录时,只需使用nodemon -w ./ 运行您的应用。 -w 代表查看目录而不是 1 个 JS 文件。很有用;当你有超过 1 个 js 时,你需要 mon

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-16
        • 2018-10-18
        • 2018-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多