Question How can I run node.js and npm from command line?

PeterK900

Basic Pleskian
Server operating system version
AlmaLinux9
Plesk version and microupdate number
18.0.77 Update #2
Node.js manager gives the path to the node and npm executable files - /opt/plesk/node/24/bin/node.

But where do I go to run these files - for example to see the version numbers with node - v and npm -v. and to install applications e.g. npm install [<package-name>]

I sense I might be missinhg something simple, so apolgies!
 
Thanks for responding to my problem. I've followed the instructions in the link but the final command nodenv local 21 gives the error nodenv: version `21' not installed .
Plesk /installer/select_components shows Nodejs support with a green tick but I can't find any details of which versions might be installed.
Thanks for any further help you can give on this.
 
P.S. I've navigated to /opt/plesk/node and see two files 24 and 26. But running nodenv local 26 gives the same error.
 
The problem was not having the location of node and npm in $PATH. printf "%s\n" $PATH shows this.

find / -iname 'node*' finds all locations of the file node. The one I want is /opt/plesk/node/26/bin

This link
provided the way to update $PATH so I can run node and npm from any folder on the site.

System wide access for all users is handled by creating a .sh file (e.g. myapp.sh) in the profile.d folder.

Create the file: sudo nano /etc/profile.d/myapp.sh
Add the line to this file: export PATH="/opt/plesk/node/nn/bin" when nn is the numeric node version - e.g. 26.

So now when I navigate to a domain folder and run node -v or npm -v I see the version numbers. Brilliant!
 
Back
Top