簡體   English   中英

nodemon 不工作

[英]nodemon not working

當我運行 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 開始正常

嘗試這個

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

"scripts":{ "start":"node app", "dev":"nodemon app" }

  1. 第二步使用代碼 npm i -D nodemon 將 nodemon 安裝為 devdependencies

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)

Nodemon 首先運行文件./app.js
但是您的啟動 npm 腳本(根據您的問題工作)運行不同的文件./bin/www/index.js

我認為您應該告訴 nodemon 哪個文件是您的入口點。
因此,您應該使用相同的值編輯 package.json 中的“main”條目,例如./bin/www 事實上,nodemon 會在 package.json 中讀取這個值,以便知道從哪個文件開始。

當您在應用程序根目錄中時,只需使用nodemon -w ./運行您的應用程序。 -w 代表查看目錄而不是 1 個 JS 文件。 很有用; 當你有 1 個以上的 js 時,你需要 mon 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM