Creating a Node.js App via the Command-Line (Advanced)
Knowledgebase Article
}
Knowledgebase Article
If you're comfortable using SSH and working in the terminal, the command-line method gives you full control over Node.js application setup and management. While the cPanel interface is user-friendly, it can become repetitive or slower when:
Using the cloudlinux-selector
CLI tool, you can:
npm
or Node useBelow is a step-by-step guide to creating and launching a Node.js app entirely from the terminal.
If SSH is not yet enabled on your account, please contact our support team and we’ll be happy to turn it on.
Once enabled, connect using an SSH client like this:
ssh youruser@yourdomain.com -p [port]
Replace [port]
with the port number we give you.
Before you can start building your app, you'll need to create the directory where it will live.
mkdir ~/mynodeapp
cd ~/mynodeapp
This folder will serve as your application root when setting up the app in the Node.js Selector later on — so make a note of the path you choose (e.g. /home/yourusername/mynodeapp
).
Within your application directory, use any terminal editor (e.g. vi
, nano
) to create your package.json
. For example, using nano:
nano package.json
Paste in your package.json
file, for example:
{
"name": "mynodeapp",
"version": "1.0.0",
"description": "A simple Node.js app using Express",
"main": "app.js",
"author": "Your Name",
"license": "MIT",
"dependencies": {
"express": "^4.18.2"
}
}
Save and exit the file.
Before you create the app in the Node.js Selector, you'll need to create (or upload) the startup file — this is usually called app.js
, server.js
, or similar.
This file must be compatible with Phusion Passenger, which is used under the hood by the Node.js Selector to serve your app.
In short:
app.listen(...)
module.exports = app
Make sure the file name matches the value you passed via --startup-file
during app creation.
Run the following command to initialise your Node.js app:
cloudlinux-selector create --json --interpreter nodejs --version 18 --app-root mynodeapp --domain yourdomain.com --app-uri app --startup-file app.js
Replace:
18
with your desired Node.js version (e.g. 14, 16, 18)mynodeapp
with your chosen application root directoryyourdomain.com
with the domain where the app will be accessibleapp
with the subdirectory for the app (or leave this blank for root domain)app.js
with the filename of your actual startup fileIf you don't include --startup-file
, it defaults to app.js
.
To install the Node.js dependencies listed in your package.json
, run:
cloudlinux-selector install-modules --json --interpreter nodejs --user yourcpaneluser --app-root mynodeapp
Replace:
yourcpaneluser
with your actual cPanel usernamemynodeapp
with the exact application root directory you used when creating the appnpm install
is executed inside the correct virtual environment, scoped specifically to your app.For example, if you created the app with:
cloudlinux-selector create --json --interpreter nodejs --version 18 --app-root myappdir --domain example.com --app-uri app
Then your install command should look like:
cloudlinux-selector install-modules --json --interpreter nodejs --user examplecpuser --app-root myappdir
This will:
package.json
file inside ~/myappdir
express
, dotenv
, etc.)If you later update your package.json
, re-run this command to install any new modules.
If you'd like to run npm
commands, debug interactively, or use Node-based build tools inside your app’s own environment, you can activate the virtual environment manually.
source /home/yourcpaneluser/nodevenv/mynodeapp/18/bin/activate && cd ~/mynodeapp
Replace:
yourcpaneluser
– with your actual cPanel usernamemynodeapp
– with your application root folder18
– with the Node.js version number you choseOnce activated, you can:
npm install
manually (if needed)package.json
(e.g. npm run build
)node app.js
(for non-server logic)To exit the virtual environment when you're done, simply type:
deactivate
Once your Node.js application has been created, you can fully control its running state using simple commands — there’s no need for process managers like pm2
or forever
. The Node.js Selector, via Phusion Passenger, handles everything automatically behind the scenes.
โ Start the app:
cloudlinux-selector start --json --interpreter nodejs --app-root ~/mynodeapp
โน Stop the app:
cloudlinux-selector stop --json --interpreter nodejs --app-root ~/mynodeapp
๐ Restart the app:
cloudlinux-selector restart --json --interpreter nodejs --app-root ~/mynodeapp
Powered by WHMCompleteSolution