1.使用express搭建一个项目,步骤如下(安装node步骤已省略)
a.全局安装express-generator(express生成器)
npm i express-generator -g
b.express一个项目
express test
c.进入到改项目根目录
cd test
d.安装依赖
npm install
2.全局安装nodemon
npm i -g nodemon
3.在项目根目录创建 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 njk css js "}
4.package.json的scripts中添加如下内容并保存文件
"dev": "nodemon ./bin/www"
添加后效果大致为:
{ "name": "test", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www", "dev": "nodemon ./bin/www" }, "dependencies": { "cookie-parser": "~1.4.3", "debug": "~2.6.9", "express": "~4.16.0", "http-errors": "~1.6.2", "jade": "~1.11.0", "morgan": "~1.9.0" }}
5.启动项目
npm run auto
或者
npm run dev
*注:若不想修该package.json文件,则在创建了 nodemon.json 文件之后,直接运行即可,具体如下
nodemon app.js