> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.elitehost.co.za/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How do I deploy a Node.js App in cPanel?

Node.js is a popular JavaScript runtime that enables developers to build fast, scalable web applications. If you’re familiar with Node.js development, you might be wondering how to host your application on a shared server. In this guide, we’ll walk you through deploying a Node.js app on cPanel.

### Step 1: Create a Node.js Application

1. **Navigate to cPanel**: In cPanel, locate and click on **Setup Node.js App** under the **Software** section.
2. **Click "Create Application"**: Select this option to begin setting up your Node.js environment.
3. **Select Node.js Version**: Choose the desired Node.js version for your application.
4. **Application Mode**: Set the mode to **Development** or **Production** - this can be changed later.
5. **Application Root**: Enter a directory name, such as `node_app`, where your application files will reside.
6. **Application URL**: Leave blank to host the app on the root domain or specify a subdirectory (e.g., `nodeapp`).
7. **Application Startup File**: Enter the filename of your main entry file, like `app.js` or `index.js`.

**Click "Create"** and wait for cPanel to initialise the Node.js environment.

### Step 2: Upload Your Application Files

1. **Open File Manager**: For easy access, right-click **File Manager** to open it in a new tab.
2. **Navigate to the Application Root Directory**: Open the directory you specified (e.g., `/node_app`).
3. **Upload Files**: Upload all necessary Node.js files, including `app.js`, `package.json`, and any additional required files, to this directory.

### Step 3: Install Dependencies

1. **Return to Setup Node.js App**: Go back to the **Setup Node.js App** interface in cPanel.
2. **Install Packages**: Click **Run NPM Install** to install all dependencies listed in your `package.json` file.

### Step 4: Configure Environment Variables (Optional)

* If your app requires environment variables, click **Add Variable** under **Environment Variables**.
* Input the **Variable Name** and **Value** for each required environment variable.
* Click **Done** and then **Save** to apply the changes.

### Step 5: Start the Application

1. **Click Start Application**: Start the application using the **Start Application** button.
2. **Verify the Application**: Open the specified **Application URL** in your browser to ensure that the app is running correctly.

### Managing and Monitoring the Application

* **Error Logs**: If issues arise, check the **stderr.log** file in the application root folder for detailed information.
* **Stop/Start/Restart Application**:  If you make changes to your code or encounter issues, you can control your application directly from the Node.js Selector in cPanel. Use the Stop button to halt the application, Start to launch it again, and Restart to reload any updates you’ve made to the code without downtime.
* **Change Node.js Version**: You can easily change the Node.js version by stopping the application and selecting a new version in the setup interface.

Following these steps will deploy your Node.js application efficiently on a cPanel account, all through the GUI and without requiring SSH access.

### Virtual Environment Command Line

If you have SSH/Terminal access through a Business or Reseller package, you can manage the app directly via the command line. Many users prefer this option for faster or more detailed control over their applications. This feature enables you to work within a secure virtual environment specifically for your app, providing convenient access to command-line tools.

1. In **Setup Python App**, click **Edit** next to your app.
2. Copy the **source** command provided next to **Enter to the virtual environment**.
3. Open **Terminal** in cPanel or log in via SSH, paste, and run the command to enter the environment.

If you have any questions or need further assistance, feel free to contact our [support team](https://my.elitehost.co.za/submitticket.php?step=2&deptid=14) or email helpdesk@elitehost.co.za.