[英]How to automate mysql database creation on Node.js with 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 開始正常
嘗試這個
"scripts":{ "start":"node app", "dev":"nodemon app" }
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 中讀取這個值,以便知道從哪個文件開始。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.