I have been following these steps as noted below in order to install npm and node on my cpanel server and prepare to launch a webapp via app.js, however, after I
mkdir ~/bin
and attempt to cp nodejs/bin/node ~/bin
as outlined in step 5
I receive the following error:
[~]# cp nodejs/bin/node ~/bin
cp: cannot stat 'nodejs/bin/node': No such file or directory
Steps for node and npm installation as viewed at Run node.js on cpanel hosting server
. Log in to your account using SSH (it is not enabled for your account contact support team).
- Download the NodeJS
wget https://nodejs.org/dist/latest/node-v10.0.0-linux-arm64.tar.xz
- Extract the NodeJS Files
tar xvf node-v10.0.0-linux-arm64.tar.xz
- Now rename the folder to nodejs name, to do this type the following command
mv node-v10.0.0-linux nodejs
- Now install node and npm binaries, type the next commands:
mkdir ~/bin
cp nodejs/bin/node ~/bin
cd ~/bin
ln -s ../nodejs/lib/node_modules/npm/bin/npm-cli.js npm
- Node.js and npm are installed on your account. To verify, type the following commands
node --version
npm --version
The ~/bin directory is in your path by default, which means you can run node and npm from any directory in your account.
- Start Node.js Application
nohup node my_app.js &
- Stop the Application
pkill node
- Integrating a Node.js application with the web server(optional)
Depending on the type of Node.js application you are running, you may want to be able to access it using a web browser. To do this, you need to select an unused port for the Node.js application to listen on, and then define server rewrite rules that redirect visitors to the application.
In a text editor, add the following lines to the .htaccess file in the/home/username/public_html directory, where username represents your account username:
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]```
<