Node v16.16.0 is installed by running the next terminal commands:
curl -s https://deb.nodesource.com/setup_16.x | sudo bash;
sudo apt install nodejs -y.
After installation, running a command:
sudo node -v
outputs:
v16.16.0
Running the same one as a www-data user:
sudo -u www-data node -v
outputs as the previous one as well:
v16.16.0
But the problem with npm command.
As long as the command runs within sudo
output has version
sudo npm -v
And the output is:
8.11.0
However, running as www-data outputs empty line.
sudo -u www-data npm -v
The same problem is for any npm command.
The question is why is this happening and how to make npm commands work for www-data user.