npm 如何解决错误:EACCES:pm2中的权限被拒绝?

mf98qq94  于 2022-12-04  发布在  其他
关注(0)|答案(3)|浏览(310)

我不知道为什么在运行pm2 status时会遇到此错误:

kaitoSwift@kaito-MacBook-Pro school-sms2 % pm2 status
node:internal/fs/utils:344
    throw err;
    ^

Error: EACCES: permission denied, open '/Users/kaitoSwift/.pm2/pm2.log'
    at Object.openSync (node:fs:585:3)
    at module.exports.Client.launchDaemon (/usr/local/lib/node_modules/pm2/lib/Client.js:228:12)
    at /usr/local/lib/node_modules/pm2/lib/Client.js:104:10
    at /usr/local/lib/node_modules/pm2/lib/Client.js:321:14
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at listOnTimeout (node:internal/timers:528:9)
    at processTimers (node:internal/timers:502:7) {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/Users/kaitoSwift/.pm2/pm2.log'
}

当我尝试使用npm install pm2 -g下载pm2时:

kevintrinidad@kaito-MacBook school-sms2 % npm install pm2 -g 
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/pm2
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/pm2'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/pm2'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/pm2'
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/kaitoSwift/.npm/_logs/2022-04-07T11_15_28_141Z-debug-0.log
qzlgjiam

qzlgjiam1#

要安装PM2,请使用以下命令:

sudo npm install -g pm2

对于pm2 status的错误,也是一样的,请尝试:

sudo pm2 status

该错误告诉您/Users/kaitoSwift/.pm2/pm2.log不存在。

mw3dktmi

mw3dktmi2#

您需要在sudo中运行此命令并验证没有其他进程在同一端口上运行。

cbeh67ev

cbeh67ev3#

It is a permission error
If you are trying to use pm2 in ubuntu server on EC2 and getting error for error: EACCES and code :-13 

Just follow these steps:
sudo su - to get to the root user permissions
then create an ecosystem.config.js file in the root folder:- 
module.exports = {
  apps : [{
    name: "server",
    script: "server.js"
  }]
}
then write pm2 start server

相关问题