nodemon可以帮忙监听node是否变化
只要node
修改了(command/Ctrl + s),nodemon
会帮我们自动重启node
安装
npm install --global nodemon
我安装的期间遇到了下面这个问题
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR! stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Murphy/.npm/_logs/2020-04-16T14_41_40_643Z-debug.log
上面现实没有权限修改node_modules,mac的话在命令行开头加上sudo就可以了(需要输入密码)想明白怎么具体操作的可以看我的这篇博客
https://blog.csdn.net/EcbJS/article/details/105189295
sudo npm install --global nodemon
安装完成后
╭────────────────────────────────────────────────────────────────╮
│ │
│ New minor version of npm available! 6.13.4 → 6.14.4 │
│ Changelog: https://github.com/npm/cli/releases/tag/v6.14.4 │
│ Run npm install -g npm to update! │
│ │
╰────────────────────────────────────────────────────────────────╯
运行命令
以app.js
为例
nodemon app.js
注意,只有通过nodemon运行起来的才可以监听,node运行起来的还是跟原来一样。