nodemon是一種工具,可在檢測到目錄中的文件更改時通過自動重新啟動節點應用程序來幫助開發基於node.js的應用程序
在編寫調試Node.js項目,修改代碼后,需要重新啟動
為了減輕手工重啟的成本,可以采用 nodemon
來代替 node
以啟動應用。當代碼發生變化時候,nodemon
會幫我們自動重啟
安裝
npm install -g nodemon
查看
$ nodemon -h Usage: nodemon [options] [script.js] [args] Options: --config file ............ alternate nodemon.json config file to use -e, --ext ................ extensions to look for, ie. js,pug,hbs. -x, --exec app ........... execute script with "app", ie. -x "python -v". -w, --watch path ......... watch directory "path" or files. use once for each directory or file to watch. -i, --ignore ............. ignore specific files or directories. -V, --verbose ............ show detail on what is causing restarts. -- <your args> ........... to tell nodemon stop slurping arguments. ……
eg:
$ nodemon app [nodemon] 2.0.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node app.js` mongodb://127.0.0.1:27017/traptor Example app listening on port 3000! 數據庫鏈接成功!
調用的也是node命令
修改代碼保存后后,會自動重啟
手動重啟,也不用停掉重啟,使用
rs
指定內存使用大小的啟動
$ nodemon --max-old-space-size=2048 app.js [nodemon] 2.0.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node --max-old-space-size=2048 app.js` mongodb://127.0.0.1:27017/traptor Example app listening on port 3000! 數據庫鏈接成功!
注:
git-bash使用ctrl+c無法終止nodemon的執行,可以使用
netstat -aon|findstr "3000"
查出進程id,終止進程
tskill 進程id
使用CMD窗口ctrl+c可以終止執行