Running Node.js Applications on Shared Hosting
Node.js is a powerful JavaScript runtime that enables you to build fast, scalable web applications and APIs. All {{COMPANY_NAME}} shared hosting plans include Node.js support through CloudLinux, allowing you to run Node.js applications without needing a VPS or dedicated server. This guide covers everything you need to know about deploying and managing Node.js applications on shared hosting.
Node.js on Shared Hosting
Our shared hosting platform supports Node.js through CloudLinux's Node.js Selector, which provides:
- Multiple Node.js versions — choose from a range of supported versions
- Application management — start, stop, restart, and monitor your applications
- npm support — install packages and manage dependencies
- Passenger integration — production-ready application serving
- No VPS required — run Node.js applications on your shared hosting plan
Tip: You do NOT need to upgrade to a VPS to run Node.js applications. Our shared hosting includes full Node.js support through CloudLinux.
Setting Up a Node.js Application in cPanel
Step 1: Access the Node.js Selector
- Log in to cPanel
- Navigate to the Software section
- Click Setup Node.js App
Step 2: Create a New Application
- Click Create Application
- Configure the application settings:
- Node.js version: Select your desired version (e.g., 18.x, 20.x)
- Application mode: Choose Production for live sites or Development for testing
- Application root: The directory containing your application (e.g., myapp)
- Application URL: The URL path for your application (e.g., your domain root or a subdirectory)
- Application startup file: The entry point of your application (e.g., app.js, server.js, or index.js)
- Click Create
Step 3: Install Dependencies
After creating the application:
- Click Run NPM Install from the application management page
- This reads your
package.jsonand installs all listed dependencies - Wait for the installation to complete
Step 4: Start the Application
- Your application should start automatically after creation
- Use the Start App / Stop App / Restart App buttons to manage it
- Visit your application URL to verify it is running
Setting Up Node.js in DirectAdmin
Using the Node.js Selector
- Log in to DirectAdmin
- Go to Extra Features > Node.js Selector (or look under Advanced Features)
- Click Create Application
- Fill in the settings:
- Node.js version: Choose from available versions
- Application root: Directory path
- Application URL: Domain or subdomain
- Startup file: Entry point file
- Click Create
- Run npm install from the interface
Using SSH (Alternative Method)
- SSH into your hosting account
- Navigate to your application directory
- Select the Node.js version:
# List available versions
nodejs_selector --list
# Use a specific version
nodejs_selector --set-version 20- Install dependencies and start:
npm installCreating a Basic Node.js Application
Here is a minimal Express.js application to get started:
package.json
{
"name": "my-website",
"version": "1.0.0",
"description": "My Node.js website",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "^4.18.0"
}
}app.js
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello from Node.js on shared hosting!');
});
app.listen(port, () => {
console.log(`Application running on port ${port}`);
});Important: On shared hosting with Passenger, you do not need to specify a port. Passenger handles the port assignment. Your app should listen on the port provided in
process.env.PORT.
Environment Variables
Manage environment variables for your application:
Through the Control Panel
- Go to the Node.js application management page
- Look for the Environment Variables section
- Add key-value pairs (e.g.,
DATABASE_URL,API_KEY) - Click Save and restart the application
Using a .env File
- Create a
.envfile in your application root:
DATABASE_URL=mysql://user:pass@localhost/dbname
API_KEY=your-api-key-here
NODE_ENV=production- Use the
dotenvpackage in your application:
require('dotenv').config();
console.log(process.env.DATABASE_URL);- Add
.envto your.gitignoreto keep secrets out of version control
Managing npm Packages
Installing Packages via Control Panel
- Edit your
package.jsonto add dependencies - Click Run NPM Install in the application management page
Installing Packages via SSH
cd ~/myapp
npm install package-name --saveUpdating Packages
npm updateTroubleshooting Node.js Applications
Application Not Starting
- Check the application log file for errors
- Verify the startup file path is correct
- Ensure all dependencies are installed (
npm install) - Check for syntax errors in your code
- Verify the Node.js version is compatible with your application
503 Service Unavailable
- The application may have crashed. Check logs and restart.
- Ensure your application does not exceed memory limits on shared hosting.
- Verify the application is listening on the correct port.
Module Not Found Errors
- Run
npm installto ensure all dependencies are present - Check that the module is listed in
package.json - Verify the correct Node.js version is selected
Application Running Slowly
- Shared hosting has resource limits. Optimize your application for memory and CPU usage.
- Use caching where possible (e.g., Redis, in-memory caching)
- Minimize the number of npm packages
- Consider using a build step to bundle your application
Changes Not Reflecting
- Restart the application after making code changes
- Clear any caching your application uses
- Check that you are editing files in the correct directory
Best Practices for Node.js on Shared Hosting
- Use production mode: Set
NODE_ENV=productionfor better performance - Handle errors gracefully: Uncaught exceptions can crash your application
- Monitor memory usage: Shared hosting has memory limits; keep your application lean
- Use process.env.PORT: Let the hosting environment assign the port
- Keep dependencies minimal: Only install packages you actually need
- Use a .gitignore: Exclude node_modules and .env from version control
- Test locally first: Always test changes on your local machine before deploying
- Use logging: Implement proper logging to diagnose issues quickly
Limitations on Shared Hosting
Be aware of these limitations:
- Memory limits: Applications must stay within your plan's memory allocation
- CPU limits: Long-running CPU-intensive tasks may be throttled
- No root access: You cannot install system-level packages
- Port restrictions: You cannot bind to arbitrary ports; use the assigned port
- Background processes: Long-running background jobs may be killed
For applications that exceed these limits, consider upgrading to a VPS plan for dedicated resources.
Related Articles
- Running Python Applications on Shared Hosting
- How to Access Your Account via SSH
- Deploying Your Website with Git
Need help with your Node.js application? Contact our support team at {{SUPPORT_EMAIL}} or visit {{SUPPORT_URL}}.