Hosting a Node.js application on cPanel may seem challenging at first glance, but with the right tools and knowledge, the process is simple and efficient. In this guide, you will learn the step-by-step process of how to set up your Node.js application on cPanel professionally, allowing it to be online and accessible to the world.
Prerequisites
Before we begin, make sure you have:
- Access to your server’s cPanel.
- Your Node.js application ready to be hosted (make sure it works locally).
- A recent version of Node.js installed on the server (we will see how to set this up in cPanel).
These requirements are essential for hosting to be carried out.
Step 1: Setting Up the Node.js Environment in cPanel
1.1: Accessing the Node.js Application Manager
- Log in to cPanel.
- Look for the Software section and click on Setup Node.js App (or something similar, depending on the cPanel theme).
1.2: Creating a New Environment
- Click the Create Application button.
- Fill in the requested information:
- Application Mode: Select
Production
(for a production environment). - Node.js Version: Choose the version of Node.js that your application supports.
- Application Root: Indicate the directory where your application is stored. For example:
myapp
. - Application URL: Define the URL through which your application will be accessed.
- Application Startup File: Enter the name of your application’s entry file, usually
app.js
orserver.js
.
- Application Mode: Select
- Click Create to create the environment.
Step 2: Uploading Application Files
2.1: Upload via File Manager
- In cPanel, go to File Manager.
- Navigate to the directory defined as Application Root.
- Upload your application files (it can be a
.zip
file with everything compressed). - Extract the files directly on the server.
2.2: Upload via FTP
- Use an FTP client, such as FileZilla, to connect to the server.
- Upload the files to the directory corresponding to Application Root.
Step 3: Installing Dependencies
- Return to Setup Node.js App in cPanel.
- Click Edit next to your application.
- Scroll to the Actions section and click Run NPM Install.
- This will install all dependencies listed in your
package.json
file.
- This will install all dependencies listed in your
Step 4: Setting Up Environment Variables
- Still on the application edit screen, locate the Environment Variables section.
- Add the necessary variables for your application to function, such as:
PORT
: Port your application will use (e.g., 3000).- Other variables like
DATABASE_URL
,API_KEY
, etc.
- Click Apply to save the changes.
Step 5: Testing and Starting the Application
- In Setup Node.js App, click the Run Application button.
- Check if the URL defined in the configuration is working.
- If you encounter errors, review the logs:
- The logs are available in the same panel, in the Application Logs section.
Step 6: Setting Up the Proxy (optional, but recommended)
To access your application without specifying a port, set up an HTTP proxy:
- Go to the Domain Manager configuration in cPanel.
- Create an entry that directs traffic from the main URL (e.g.,
https://meusite.com
) to the Node.js application address.
Congratulations! Your Node.js application is configured and running on cPanel. Hosting on cPanel may be slightly different from environments like Docker or VPS, but with these steps, you have a practical way to manage your application on shared servers.
If you are looking for a solution to host your applications practically and reliably, master da web offers hosting plans with support for cPanel, and an optimized environment for node.JS. Try it and discover how easy it is to get secure and efficient hosting.
Do you want access to more tutorials like this? Check out our blog or YouTube channel for more information and tips like this!