Node.js & Python Apps
CloudLinux provides application selectors that let you run Node.js and Python applications on your shared hosting account, complete with version management and virtual environments.
Setting Up a Node.js Application
Creating the Application
- Log into cPanel.
- Scroll to the Software section and click Setup Node.js App.
- Click Create Application.
- Configure the following settings:
- Node.js version: Select the version your application requires (e.g., 18, 20, 22).
- Application mode: Choose
Developmentwhile testing orProductionfor a live site. - Application root: The directory containing your app files, relative to your home directory (e.g.,
myapp). - Application URL: The domain and path where the app will be accessible (e.g.,
yourdomain.com). - Application startup file: The entry point for your app (e.g.,
app.jsorserver.js).
- Click Create to set up the application.
Installing Dependencies
After creating your application, you need to install your npm packages:
- On the Node.js app page, find your application in the list.
- Click the pencil icon to edit the application.
- Click Run NPM Install to install all dependencies from your
package.jsonfile. - Once the installation completes, click Restart to apply the changes.
Note
You can also manage your application from the command line via SSH. When you create an app through the selector, cPanel shows you the command to activate the virtual environment, which sets up the correct Node.js version and PATH for your terminal session.
Environment Variables
To set environment variables for your Node.js app:
- Edit your application in the Node.js app selector.
- Scroll down to the Environment variables section.
- Click Add Variable, enter the name and value, then click Save.
- Restart the application for the variables to take effect.
Setting Up a Python Application
Creating the Application
- Log into cPanel.
- Scroll to the Software section and click Setup Python App.
- Click Create Application.
- Configure the following settings:
- Python version: Select the version your application requires (e.g., 3.11, 3.12).
- Application root: The directory containing your app files (e.g.,
myflaskapp). - Application URL: The domain and path where the app will be accessible.
- Application startup file: The WSGI entry point (e.g.,
passenger_wsgi.py). - Application Entry point: The WSGI callable in your startup file (e.g.,
application).
- Click Create.
Installing Python Packages
You can install Python packages through the app selector interface or via the command line:
Using the interface:
- Edit your Python application.
- Scroll to the Configuration files section and add your
requirements.txtpath. - Click Run Pip Install to install all packages listed in the file.
- Restart the application.
Using SSH:
source /home/username/virtualenv/myflaskapp/3.11/bin/activate
pip install flask gunicorn
pip freeze > requirements.txt
Tip
Always use a
requirements.txt file to track your Python dependencies. This makes it easy to reinstall packages if you need to recreate your application.
Common Application Frameworks
Express.js (Node.js)
A minimal app.js for Express:
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello from Express!');
});
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});
Flask (Python)
A minimal passenger_wsgi.py for Flask:
from flask import Flask
application = Flask(__name__)
@application.route('/')
def hello():
return 'Hello from Flask!'
Managing and Restarting Apps
You can manage your running applications from the Node.js or Python app selector page in cPanel:
- Restart: Click the restart icon to reload your application after making code changes.
- Stop: Temporarily stop the application from running.
- Delete: Remove the application configuration entirely. Your files will remain on disk.
Warning
Node.js and Python applications consume entry processes and memory from your hosting account's resource limits. Monitor your resource usage if your application handles significant traffic.