NodeJS on production server - permissions

I want to have nodeand npmfor any user in the system.

On our team, when someone updates the code from git, they run: sudo -u www-data git pull

So, no matter what project it is, we always go through the user www-data.

Now we have a new Node project and we need to do the same. There is no way on our production server to rely on a single user to handle everything about Node — what if he leaves tomorrow?

So, we do not use NVM, but install Node as the root as described here

All this is fine, and all users see nodeand npmexecutable files. Problems begin when we are actually trying to use them.

What do you want to do:

cd /var/www/node_project
sudo -u www-data git pull
sudo -u www-data npm install

This does not work on the last command because it is npmtrying to write the file lockto my home directory. So: /home/user/.npminstead of going somewhere globally or /var/www/.npmwhich will be the home directory for the www-data user.

Similarly, after installation

sudo npm install -g typings

And then running sudo -u www-data typings install, you get an error message because it is trying to write/home/user/.config/configstore/insight-typings.json

Can someone comment on how to properly install Node on the server? If I run sudo -u www-data, why is npm ins still in my home folder?

+4
source share
1 answer

You can specify a directory for global installations from some user:

set prefix = ~/.where_to_installto~/.npmrc

PATH (, ~/.npm/bin)

Btw, www- ?

+2

All Articles