# Creating a Node.js app via the command-line (advanced)

> Use SSH and the cloudlinux-selector CLI to create and manage a Node.js app without touching the cPanel interface.

Source: https://www.kualo.com/knowledgebase/dev-languages/creating-a-nodejs-app-via-the-command-line-advanced
Updated: 2026-06-04

---

If you are 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 works well for one-off tasks, the CLI approach is faster and more repeatable when:

- Deploying multiple applications
- Working with version control or automation
- Troubleshooting with real-time feedback
- Managing apps more flexibly via scripts

Using the `cloudlinux-selector` CLI tool, you can:

- Create applications programmatically
- Install dependencies without using the GUI
- Enter the app's virtual environment for direct `npm` or Node use
- Start, stop, and restart apps without needing cPanel access

:::info
This method is aimed at developers and advanced users who want to streamline app management through SSH.
:::

## Step 1: log in via SSH

If SSH is not yet enabled on your account, contact our support team and we will be happy to turn it on.

:::warning
We use a non-standard SSH port. We will provide the correct port number when SSH access is granted.
:::

Once enabled, connect using an SSH client:

```bash
ssh youruser@yourdomain.com -p [port]
```

Replace `[port]` with the port number we give you.

## Step 2: create and navigate to your application directory

Create the directory where your app will live, then move into it:

```bash
mkdir ~/mynodeapp
cd ~/mynodeapp
```

This folder will serve as your application root when you register the app with the Node.js Selector in the next steps - make a note of the full path (for example, `/home/yourusername/mynodeapp`).

## Step 3: create the package.json file

Use any terminal editor to create your `package.json`. For example, using nano:

```bash
nano package.json
```

Paste in your package definition, for example:

```json
{
  "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.

## Step 4: set up the application startup file

Before you register the app with the Node.js Selector, you 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 the Node.js Selector uses to serve your app.

:::info
For full guidance and code examples, see: [Writing the startup file (app.js or similar)](/knowledgebase/nodejs/enabling-nodejs-in-cpanel)
:::

In short:

- Do not use `app.listen(...)`
- Instead, export your app instance using `module.exports = app`

:::warning
If the startup file is not structured correctly, or you use an incorrect file name, your application may fail to start and return a 503 error.
:::

Make sure the file name matches the value you pass via `--startup-file` when creating the app.

## Step 5: create the application

Run the following command to register your Node.js app:

```bash
cloudlinux-selector create --json --interpreter nodejs --version 18 --app-root mynodeapp --domain yourdomain.com --app-uri app --startup-file app.js
```

Replace the following values to match your setup:

| Placeholder | Replace with |
|---|---|
| `18` | Your desired Node.js version (for example, 20 or 22) |
| `mynodeapp` | Your chosen application root directory |
| `yourdomain.com` | The domain where the app will be accessible |
| `app` | The subdirectory URI for the app (omit or leave blank for the root domain) |
| `app.js` | The filename of your actual startup file |

If you omit `--startup-file`, it defaults to `app.js`.

## Step 6: install Node modules

To install the dependencies listed in your `package.json`, run:

```bash
cloudlinux-selector install-modules --json --interpreter nodejs --user yourcpaneluser --app-root mynodeapp
```

Replace `yourcpaneluser` with your actual cPanel username and `mynodeapp` with the exact application root directory you used when creating the app.

:::info
This command runs `npm install` inside the correct virtual environment, scoped specifically to your app.
:::

For example, if you created the app with:

```bash
cloudlinux-selector create --json --interpreter nodejs --version 18 --app-root myappdir --domain example.com --app-uri app
```

Then your install command should be:

```bash
cloudlinux-selector install-modules --json --interpreter nodejs --user examplecpuser --app-root myappdir
```

This will:

- Enter the correct virtual environment for your app
- Detect the `package.json` file inside `~/myappdir`
- Install all specified dependencies (for example, `express`, `dotenv`)

If you later update your `package.json`, re-run this command to install any new modules.

## Optional: enter the virtual environment

If you want 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:

```bash
source /home/yourcpaneluser/nodevenv/mynodeapp/18/bin/activate && cd ~/mynodeapp
```

Replace:

- `yourcpaneluser` with your actual cPanel username
- `mynodeapp` with your application root folder
- `18` with the Node.js version number you chose

Once activated, you can:

- Run `npm install` manually if needed
- Execute any scripts defined in your `package.json` (for example, `npm run build`)
- Test your application logic with `node app.js` (for non-server logic)

To exit the virtual environment when you are done, type:

```bash
deactivate
```

:::info
You do not need to keep the virtual environment active for your app to run - this is only for manual CLI work via SSH.
:::

## Managing the application from the CLI

Once your Node.js application has been created, you can control its running state with simple commands - there is 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:**

```bash
cloudlinux-selector start --json --interpreter nodejs --app-root ~/mynodeapp
```

**Stop the app:**

```bash
cloudlinux-selector stop --json --interpreter nodejs --app-root ~/mynodeapp
```

**Restart the app:**

```bash
cloudlinux-selector restart --json --interpreter nodejs --app-root ~/mynodeapp
```

:::info
These commands are all you need to manage the application lifecycle. Passenger ensures your app is properly served over the web once it is started - no custom scripts or background processes required.
:::

---

_Source: Kualo Knowledgebase — https://www.kualo.com/knowledgebase/dev-languages/creating-a-nodejs-app-via-the-command-line-advanced · © Kualo Ltd._
