0

I'd like to install packages like these on MacOSX, but interested in Windows or Linux versions too:

npm install express npm install swig npm install mongodb npm install consolidate npm install http-auth 

If I call npm without sudo, some of them will fail:

Error: EACCES, open '/Users/me/.npm/cookie/0.1.2/package.tgz' npm ERR! { [Error: EACCES, open '/Users/me/.npm/cookie/0.1.2/package.tgz'] npm ERR! errno: 3, npm ERR! code: 'EACCES', npm ERR! path: '/Users/me/.npm/cookie/0.1.2/package.tgz', npm ERR! parent: 'express' } npm ERR! npm ERR! Please try running this command again as root/Administrator 

If I install with sudo, the files end up wherever my current directory is, and there under node_modules.

If I use the -g command, I get the access problem.

If I use the -g with sudo, it installs, but the node app cannot find the packages:

module.js:340 throw err; ^ Error: Cannot find module 'express' 

Am I missing something important? What is the correct way to install these packages? (I was told, that installing globally should be preferred, so that all apps are always linked to the most up-to-date package version, so if that makes a difference, please let me know)

2 Answers 2

0

Node.js will traverse folders upwards until it finds your package, so you can install all in your home folder:

cd ~ npm install express 
1
  • Show us the error please Commented Jul 31, 2014 at 12:59
0

From the npm help 5 npm-foldersman page:

  • Local install (default):
    puts stuff in ./node_modules of the current package root.

  • Global install (with -g):
    puts stuff in /usr/local or wherever node is installed.

  • Install it locally if you're going to require() it.

  • Install it globally if you're going to run it on the command line.

  • If you need both, then install it in both places, or use npm link.

The only time I used sudo was the install of nw because I wanted it to be linked in /usr/bin. After the invoke with sudo I ran into similar Errors, because root as owned my ~/.npm/_locks directory.

Every install ran into Error, until I chown ~/.npm and ~/.npm/_locks back to my user.

Follow the instruction of man page and check ~/.npm everytime you sudo.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.