6

I'm just trying to install nodemon or supervisor using terminal, and I keep getting this error which I don't understand. I tried running as the administrator with sudo npm install supervisor -g which seemed to work, but than didn't when i deleted/added some js code. Any ideas?

Squirrels-MacBook-Air:lesson7_examples Squirrel$ npm install nodemon -g
npm http GET https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/nodemon
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/nodemon',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/nodemon',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.4.1
npm ERR! command "node" "/usr/local/bin/npm" "install" "nodemon" "-g"
npm ERR! cwd /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose/npm-debug.log
npm ERR! not ok code 0
Squirrels-MacBook-Air:lesson7_examples Squirrel$ 

P.S. I'm running this on a pre-existing template and my dependencies are

  "dependencies": {
    "mongoose": "~3.6.15",
    "express": "~3.3.4",
    "jade": "~0.34.1",
    "email-validator": "~0.1.2"
  }

When I tried sudo this is what happened:

sudo npm install supervisor -g --save 
Password:
npm http GET https://registry.npmjs.org/supervisor
npm http 304 https://registry.npmjs.org/supervisor
/usr/local/bin/node-supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
/usr/local/bin/supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
supervisor@0.5.6 /usr/local/lib/node_modules/supervisor

Which seemed to work. But than in the application code I began to add and delete javascript and click save, yet the effects wouldn't take place unless I restarted the server within terminal.

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
Squirrl
  • 3,870
  • 9
  • 41
  • 75
  • Your question isn't clear. Did it work using `sudo`? What exactly did you do when you said "*seemed to work, but than didn't when i deleted/added some js code*"? – Paul Mougel Nov 15 '13 at 20:38
  • There I added what happened when I used sudo above. – Squirrl Nov 15 '13 at 20:46
  • Indeed, using sudo looks like it worked. The fact that your server behavior isn't updated when you save your file is probably related to a bad usage of nodemon. I'd suggest opening another question, as your nodemon install looks fine. – Paul Mougel Nov 15 '13 at 20:52
  • I deleted a chunk of code in my application which had no effect when I refreshed the browser, but only when I restarted the server in terminal. Shouldn't that use nodemon or supervisor? Thanks very much for ur help. – Squirrl Nov 15 '13 at 20:54
  • 1
    Do you run your application like [this](https://github.com/remy/nodemon#usage)? Do you watch the needed directory as stated [here](https://github.com/remy/nodemon#monitoring-multiple-directories)? – Paul Mougel Nov 15 '13 at 20:56
  • Ok I see what I was doing wrong. I was typing `node app.js` and not `nodemon app.js`. Thanks a lot. I feel pretty dumb. That is how I'm suppose to do, right? Thanks again. – Squirrl Nov 15 '13 at 21:09
  • 1
    Exactly! That's why `nodemon` has to be installed globally, so that you can use it as an executable anywhere, just as you'd use the `node` command. – Paul Mougel Nov 15 '13 at 21:11

3 Answers3

11

Late to the party, but it is important to note that you should avoid using sudo when npm installing. It is a huge security risk to sudo npm install as you are giving arbitrary scripts root access to your machine.

Instead you should make yourself the owner of the directories in which the NPM

sudo chown -R $USER /usr/local

and then

sudo chown -R $USER ~/.npm

Now you should be able to run the commands without sudo:

npm install supervisor -g --save

Duane
  • 4,161
  • 1
  • 22
  • 26
7

You're encountering an EACCES error, which means you don't have the rights to create a directory in /usr/local/lib/node_modules/nodemon as a standard user in Mac OS X.

There are two solutions:

  • Run the same command as a superuser, using sudo. The package will be installed in /usr/local/lib/node_modules.
  • Change npm's settings to install all of your global packages into one of your private folders, that your user has ownership of. See this relevant answer that explains step-by-step the process.
Community
  • 1
  • 1
Paul Mougel
  • 15,428
  • 5
  • 50
  • 61
  • I tried `sudo npm install supervisor -g --save` which seemed to pass, but than didn't work. For instance deleting a chunk of code in my application had no effect when I refreshed the browser, but only when I restarted the server in terminal. – Squirrl Nov 15 '13 at 20:50
2

I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv).

Install:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash

Then add . ~/.nvm/nvm.sh to your ~/.bashrc, ~/.profile, or ~/.zshrc

Usage:

If you wanted to use version 0.10, run nvm install 0.12.7 (or nvm install stable), then nvm use 0.12.7.

Install your libs, EACCESS error-free, and go to town. npm install -g supervisor works just fine!

To load a specific version default in new tabs, use the command nvm alias default 0.12.7

Pete Karl II
  • 3,551
  • 3
  • 19
  • 27
  • 1
    To make a version of node default using NVM the proper command is `nvm alias default 0.12.7`. All new tabs will open with default version running. – Duane Jul 21 '15 at 18:11