Reputation: 858
On my box I have the Node and NPM binaries installed under /opt/node/bin. And the path is added properly.
node -v
and
npm -v
work fine. When I create a file and run it with node all works as expected. However, when I run:
npm init
the program fails to write package.json because it does not have write permission. I use:
sudo npm init
I get a file with owner and group of 0 0 and so any regular users cannot modify this file. I don't want to have to chown every file node/npm generates.
Is there way to get node/npm to run as a user in the same group as my other users and have write permissions to the same directories?
Upvotes: 1
Views: 2547
Reputation: 10501
You could simply chown
your /opt/
directory and future calls to npm init
will be owned by you. Better yet, work in your /home
folder and make sure npm and node are in your $PATH
. This way you don't need to worry about permissions for initializing a new node module. You will, however, need to use sudo
to install packages globally. This is bad practice according to the maintainer of Nodejs:
http://howtonode.org/introduction-to-npm
I would follow along with his setup there. As he mentions, its very dangerous to give root access to a package manager.
Upvotes: 4