I want to have node and npm available for whatever user is on the system.
In our team, when someone updates code from git they run:sudo -u www-data git pull
So whatever project it is, we always go through www-data user.
Now we have new Node project and need to do the same. There is no way that on our production server we will rely on one user handling everything about node - what if he leaves tomorrow?
So we are not using NVM, but installing Node as a root as described here
Its all fine, and all users see node and npm executable. Problems start when we actually try to use them.
What you want to do is:
cd /var/www/node_project
sudo -u www-data git pull
sudo -u www-data npm install
This fails on last command, because npm is trying to write lock file in my home directory. So:/home/user/.npm instead of somewhere globally or /var/www/.npm which would be home directory for www-data user.
Similar to that, after installing
sudo npm install -g typings
And then running sudo -u www-data typings install you get an error, because it is trying to write /home/user/.config/configstore/insight-typings.json
Could someone please elaborate how to actually properly install node on server? If I run sudo -u www-data how come npm ins still going into my home folder?
You can specify directory for global installs from some user:
set prefix = ~/.where_to_install in ~/.npmrc
then add in PATH variable proper location for executables (like ~/.npm/bin)
Btw, what is home dir for www-data in your case?