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.
Navigate to cPanel: In cPanel, locate and click on Setup Node.js App under the Software section.
Click "Create Application": Select this option to begin setting up your Node.js environment.
Select Node.js Version: Choose the desired Node.js version for your application.
Application Mode: Set the mode to Development or Production - this can be changed later.
Application Root: Enter a directory name, such as node_app, where your application files will reside.
Application URL: Leave blank to host the app on the root domain or specify a subdirectory (e.g., nodeapp).
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.
Open File Manager: For easy access, right-click File Manager to open it in a new tab.
Navigate to the Application Root Directory: Open the directory you specified (e.g., /node_app).
Upload Files: Upload all necessary Node.js files, including app.js, package.json, and any additional required files, to this directory.
Return to Setup Node.js App: Go back to the Setup Node.js App interface in cPanel.
Install Packages: Click Run NPM Install to install all dependencies listed in your package.json file.
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.
Click Start Application: Start the application using the Start Application button.
Verify the Application: Open the specified Application URL in your browser to ensure that the app is running correctly.
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.
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.
In Setup Python App, click Edit next to your app.
Copy the source command provided next to Enter to the virtual environment.
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 or email helpdesk@elitehost.co.za.
Step 1: Create a Node.js Application
Navigate to cPanel: In cPanel, locate and click on Setup Node.js App under the Software section.
Click "Create Application": Select this option to begin setting up your Node.js environment.
Select Node.js Version: Choose the desired Node.js version for your application.
Application Mode: Set the mode to Development or Production - this can be changed later.
Application Root: Enter a directory name, such as node_app, where your application files will reside.
Application URL: Leave blank to host the app on the root domain or specify a subdirectory (e.g., nodeapp).
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
Open File Manager: For easy access, right-click File Manager to open it in a new tab.
Navigate to the Application Root Directory: Open the directory you specified (e.g., /node_app).
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
Return to Setup Node.js App: Go back to the Setup Node.js App interface in cPanel.
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
Click Start Application: Start the application using the Start Application button.
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.
In Setup Python App, click Edit next to your app.
Copy the source command provided next to Enter to the virtual environment.
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 or email helpdesk@elitehost.co.za.
Updated on: 25/10/2024
Thank you!