为什么我不能下载nodemon?

Why cannot i download nodemon?

我正在尝试下载 nodemon,但不确定为什么无法下载。我遇到以下错误?

npm install -g nodemon

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/nodemon'
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/ryandevasia/.npm/_logs/2021-12-04T05_47_29_366Z-debug.log

下载模块必须做什么?

EACCES 错误意味着 npm 没有安装全局包的权限。为此,您需要使用 sudo 运行 作为 root(具有 npm 全局目录的权限)的命令。因此,您可以 运行 sudo npm install -g nodemon 使用管理员帐户,在您输入密码后它会起作用。

尝试使用 sudo 安装:

sudo npm install -g nodemon

通常最好将 nodemon 作为开发依赖安装

npm i -d nodemon

这样您就可以将其构建到您的脚本中并有助于协作:

"start" : "nodemon index.js"