Author Topic: User with SSH can't run node commands on shell  (Read 97 times)

0 Members and 2 Guests are viewing this topic.

Offline
*
User with SSH can't run node commands on shell
« on: September 20, 2024, 01:04:54 PM »
Hi!

I have a CWP Pro server with Nodejs applications and want to allow users to run node commands like "npm run build" in shell access.
I'm testing with one user that already runs Nodejs applications but can't run these commands on shell.

It said:
-bash: npm: command not found

There something missed on CWP pannel user's configuration?

Thanks!

Offline
**
Re: User with SSH can't run node commands on shell
« Reply #1 on: September 20, 2024, 06:55:14 PM »
Try:
Code: [Select]
/opt/nvm/versions/node/vXX.XX.XX/bin/npmwhere vXX.XX.X is the version of nodejs you want to use (v14.15.3, v16.20.2, etc).

Offline
*
Re: User with SSH can't run node commands on shell
« Reply #2 on: September 23, 2024, 02:05:31 PM »
Hi!

I got this:

[xxxx@xxxx ~]$ /opt/nvm/versions/node/v18.19.1/bin/npm
/usr/bin/env: ‘node’: No such file or directory

inside /opt/nvm/versions/node/v18.19.1/bin/ I have:

drwxr-xr-x 2 xxxx xxxx       56 Feb 13  2024 .
drwxr-xr-x 6 root    root         108 Mar 22  2024 ..
lrwxrwxrwx 1 xxxx xxxx       45 Feb 13  2024 corepack -> ../lib/node_modules/corepack/dist/corepack.js
-rwxr-xr-x 1 xxxx xxxx 91859064 Feb 13  2024 node
lrwxrwxrwx 1 xxxx xxxx       38 Feb 13  2024 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 xxxx xxxx       38 Feb 13  2024 npx -> ../lib/node_modules/npm/bin/npx-cli.js

xxxx is the customer user.

If I run that "node" file above, it runs, but npm (link above) not run.

I installed node environment using CWP server web interface, all automatic.

Thanks!



Offline
**
Re: User with SSH can't run node commands on shell
« Reply #3 on: September 23, 2024, 08:50:08 PM »
Run:

Code: [Select]
export PATH=/opt/nvm/versions/node/vXX.XX.XX/bin:$PATH
in shell as the regular user and then:

Code: [Select]
/opt/nvm/versions/node/vXX.XX.XX/bin/npm
If it work then just add:

Code: [Select]
export PATH=/opt/nvm/versions/node/vXX.XX.XX/bin:$PATH
into ~/.bashrc of the user (if the user uses bash)

Offline
*
Re: User with SSH can't run node commands on shell
« Reply #4 on: September 26, 2024, 12:11:10 PM »
Hi!

Worked!

This could be added to CWP new implementation as automatically in case user account has NodeJS enabled.


Thank you!