A Kundu
A Kundu

Reputation: 1

Trying to install Nodemon globally but getting error

I have tried installing Nodemon locally to Node js and globally. When I create locally the CLI doesn't accept nodemon as a command; so I tried to install Nodemon globally, which gives this error:

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!   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/akashdeep/.npm/_logs/2021-05-15T09_44_48_698Z-debug.log

Upvotes: 0

Views: 739

Answers (3)

Rahul Khunt
Rahul Khunt

Reputation: 683

NEVER user npm with sudo. It will mess up the permissions with node_modules folder.

First check the folder permission of the path /usr/local/lib/node_modules by running command

ls -la /usr/local/lib/

Most likely you'll see that the ownership of that folder belongs to 'root'

You need to change the ownership from root to current user.

sudo chown -R <username> /usr/local/lib/node_modules

Here username is your current username. after running the command, check the permission again. It should change from root to current user. Then try installing the nodemon globally and it should not throw any error. And never run npm with sudo command.

Upvotes: 2

hong4rc
hong4rc

Reputation: 4103

You must run it with root permission (like Alan Tishin).

If you don't want to install packages globally without root permission, follow this:

Upvotes: 1

Alan Millirud
Alan Millirud

Reputation: 1172

globally, try to install with sudo

sudo npm i -g nodemon

for locally, in your package.json

add command to scripts

{
   "scripts": {
       "nodemon": "nodemon index.js" 
     }
}

where index.js is your startup js file with any name

then in cli run

npm run nodemon

Upvotes: 2

Related Questions