SOLVED Installing a Node.JS application on cPanel verison 80

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
I have installed Node.js with yum install ea-nodejs10 but version check are not working.

Following command not working.

Code:
node --version

npm --version
Also node app run command not working

Code:
-bash: /node: No such file or directory
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
I need Run the script by executing the following at the command line. We want to run this command in a screen or something similar.

Code:
node app.js
So need to use this following the command?

Code:
/opt/cpanel/ea-nodejs10/bin/node app.js
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello @Nirjonadda,

I recommend installing the application as a cPanel user in order to take advantage of the Application Manager feature and the How to Install A Node.js Application tutorial. Using this approach, you can edit the /home/$username/.bashrc file to export specific paths to the user's environment in order to execute commands such as "npm install" from the application's source directory.

Are you installing an open source application that's hosted on GitHub? If so, feel free to post the GitHub URL here and I'll provide you with the steps you should take to install it.

Thanks!
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
Are you installing an open source application that's hosted on GitHub? If so, feel free to post the GitHub URL here and I'll provide you with the steps you should take to install it.
No, I am using Discord Integration for xenforo.

Allowing the bot to appear online:
This is a slightly more advanced feature that you'll need to setup yourselves. Eventually, I hope to expand this part of the add-on but until then, here's the run down:
  1. You'll need to install node on your server. Contact your host or sysadmin if you're unsure of how to do this.
  2. Download the add-on's zip file, navigate to the "bot" folder in the zip root and open config.json.
  3. Set the token to the value you copied from your Discord Web API application when you installed the add-on.
  4. Set the status field to anything you want. It'll read "Playing {status}" on your server.
  5. Run the script by executing the following at the command line. You'll want to run this command in a screen or something similar.
Code:
node app.js
folder paths:

Code:
/public_html/src/addons/NF/Discord/_extra/bot/app.js
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello @Nirjonadda,

You can complete the following steps to install that application:

1. Log in to the server via SSH as the cPanel user.
2. Create the application's directory, relative to your home directory. EX:

Code:
mkdir /home/$username/nodejsapp
3. Upload the application's .zip file to /home/$username/nodejsapp and unzip it within this directory. EX:

Code:
cd /home/$username/nodejsapp
unzip $application-name.zip
4. Browse to the extracted "bot" sub-directory and edit the config.json file per that addon's instructions.
5. From the "bot" sub-directory, complete steps 2-4 on the previously linked tutorial.

Let me know if you encounter any trouble with these instructions.

Thank you.
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
Let me know if you encounter any trouble with these instructions.
Not working Test the application.

Code:
[[email protected] ~]$ /opt/cpanel/ea-nodejs10/bin/node app.js
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '/home/nadda/app.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
[[email protected] ~]$ curl http://127.0.0.1:3000
curl: (7) Failed connect to 127.0.0.1:3000; Connection refused
[[email protected] ~]$
or

Code:
[[email protected] ~]$ /opt/cpanel/ea-nodejs10/bin/node /home/nadda/nodejsapp/discord_bot/app.js
Aborted (core dumped)
[[email protected] ~]$
How to Register the application? What need add for Application URL and Path?

ScreenShot01103.png
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
Get this with step 1 Install the application.

Code:
[[email protected] ~]$ /opt/cpanel/ea-nodejs10/bin/node /home/nadda/nodejsapp/app.js
node[110]: pthread_create: Resource temporarily unavailable
Server running at http://127.0.0.1:3000/
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
[[email protected] ~]$ /opt/cpanel/ea-nodejs10/bin/node app.js
You must browse to the directory where app.js exists before running the above command.

node[110]: pthread_create: Resource temporarily unavailable
Can you try installing the test application provided in the example on the How To Install A Node.JS Application tutorial first and verify it works properly? This will help us rule out whether there's a global issue or an issue specific to your application.

Thank you.
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
You must browse to the directory where app.js exists before running the above command.
Yes but only working in /home/$username/public_html directory, not work in /home/$username/ directory. App run closed when close the web browser tab. So how can made app running all time?

Can you try installing the test application provided in the example on the How To Install A Node.JS Application tutorial first and verify it works properly? This will help us rule out whether there's a global issue or an issue specific to your application.
Issue are same, this from test application provided in the example.

Code:
[[email protected] ~]$ /opt/cpanel/ea-nodejs10/bin/node /home/nadda/nodejsapp/app.js
node[110]: pthread_create: Resource temporarily unavailable
Server running at http://127.0.0.1:3000/
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
node[110]: pthread_create: Resource temporarily unavailable
I'm unable to reproduce this error message when installing the example Node.js application per the documented instructions. Can you open a support ticket so we can take a closer look at your system to see what's leading to this error message?

Thank you.
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
I'm unable to reproduce this error message when installing the example Node.js application per the documented instructions. Can you open a support ticket so we can take a closer look at your system to see what's leading to this error message?

Thank you.
OK But please can you let me know about only working in /home/$username/public_html directory, not work in /home/$username/ directory. App run closed when close the web browser tab. So how can made app running all time?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
OK But please can you let me know about only working in /home/$username/public_html directory, not work in /home/$username/ directory. App run closed when close the web browser tab. So how can made app running all time?
Hello @Nirjonadda,

A couple of points:

1. You can use cPanel >> Application Manager to enable the application:

Application Manager - Version 78 Documentation - cPanel Documentation

2. If you want your application to automatically restart upon modification, create an empty file named restart.txt within the application's tmp directory (e.g. /home/username/nodejsapp/tmp/restart.txt). The restart.txt file directs Mod_Passenger to restart the application automatically after it's modified. You must create the empty restart.txt file each time that you want Mod_Passenger to restart the application.

Thank you.
 

Nirjonadda

Well-Known Member
May 8, 2013
752
28
78
cPanel Access Level
Root Administrator
1. You can use cPanel >> Application Manager to enable the application so it continues to run after closing your shell session or web browser tab:
Yes enabled but the application are not continues to run after closing shell session or web browser tab.

ScreenShot01106.png

ScreenShot01107.png

Also showing this error:

ScreenShot01108.png
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Can you proceed to open a support ticket so we can take a closer look at your system to see the error in action? You can post the ticket number here and we'll link this thread to it.

Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello,

To update, the issue reported as part of ticket 12316397 was caused by custom redirect rules added to the /home/username/public_html/.htaccess file preventing the application URL from loading in the web browser.

@Tarak Nath Let me know of any specific issues you encounter when installing NodeJS applications.

Thanks!
 

jasoncollege24

Active Member
Mar 25, 2012
44
11
58
Portsmouth, Virginia, United States
cPanel Access Level
Root Administrator
Like the OP, I'm trying to install a Discord bot, but this one I made myself.

Example dirs, and domain for my issue are as follows:
My home: /home/jay
My app: /home/jay/bots/bot.js
domain: (used to register/deploy the app) bots.jaysite.com

if I run /opt/cpanel/ea-nodejs10/bin/node bot.js from within /home/jay/bots the bot launches as intended, then dies when the terminal is closed (as expected). if I launch the url in my browser, i get a 403.

I was previously using PM to run the bot, but that required me to remember commands to stop, and restart the bot on updates. This method will be much easier, if I can get it to work.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
My app: /home/jay/bots/bot.js
Hello @jasoncollege24,

The app.js file is the application's default startup file. We recommend that you create the file with this exact name because Passenger searches for this filename when it attempts to run the application.

If you need to use a filename other than app.js as the application's default startup file, you must manually edit the following files:

/etc/apache2/conf.d/userdata/ssl/2_4/$username/$domain.tld/$nodejsapp.conf
/etc/apache2/conf.d/userdata/std/2_4/$username/$domain.tld/$nodejsapp.conf
Replace the entries with the $ symbol in the file paths quoted above with the actual names associated with your specific account, domain, and application.

You must open the above files in the command line text editor of your preference and add the following entries (replace index.js with the name of your preference):

PassengerStartupFile bot.js
PassengerAppType node
Let me know if this helps.

Thank you.