
Table of Contents
Can You Run Node.js on Shared Hosting?
The short answer is yes — provided your hosting provider has Phusion Passenger installed. Phusion Passenger is an application server that integrates with Apache (used by DirectAdmin) and can run Node.js, Python, and Ruby applications directly, without requiring a separate process manager.
AsiaGB Hosting supports Phusion Passenger on all DirectAdmin plans, which means you can deploy a Node.js application such as Express.js on shared hosting without needing a VPS.
Shared hosting is ideal for small to medium Node.js apps such as REST APIs, backend services, or Express.js apps with moderate traffic. For high-traffic production workloads or Next.js SSR, consider an AsiaGB VPS starting at 500 THB/month.
What Is Phusion Passenger?
Phusion Passenger (commonly called "Passenger") is a web application server that integrates directly with Apache or Nginx. It acts as the bridge between the web server and your Node.js application.
Instead of manually:
- Running
node app.jsand managing ports yourself - Using PM2 or Forever to keep the process alive
- Configuring a Reverse Proxy in Nginx
Passenger handles all of this automatically. When an HTTP request arrives, Passenger starts the Node.js process, forwards the request, and automatically restarts the process if it crashes.
Prerequisites
- A hosting plan that supports Phusion Passenger (DirectAdmin)
- SSH access to run npm install
- A domain or subdomain to deploy your Node.js app on
- An
app.jsorserver.jsentry file - A
package.jsonlisting all dependencies
Step-by-Step Setup on DirectAdmin
1. Create a Domain or Subdomain in DirectAdmin
Log in to DirectAdmin → Domain Setup → add a subdomain such as api.yourdomain.com specifically for your Node.js app. If you want to run it on the root domain, use public_html directly.
2. Upload Files to the Document Root
Upload all Node.js project files to the document root of that domain, for example /home/username/domains/api.yourdomain.com/public_html/. You can use SFTP or FileZilla.
3. Create .htaccess to Enable Phusion Passenger
Create a .htaccess file in the document root with the following content:
PassengerEnabled on
PassengerNodejs /usr/bin/node
PassengerStartupFile app.js
PassengerAppType node
Change app.js to match your actual entry point file (could be server.js, index.js, etc.).
4. Verify Apache Has the Passenger Module
If Phusion Passenger is already installed on your hosting, the .htaccess above is sufficient. If the app does not work, contact your hosting support to enable Passenger on your account.
Configuring package.json and app.js
Sample package.json for an Express.js app:
{
"name": "my-api",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
And a basic app.js:
const express = require('express');
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
res.json({ message: 'Hello from Node.js on Hosting!' });
});
app.get('/api/status', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// Phusion Passenger provides the port via the PORT environment variable
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
Phusion Passenger automatically assigns a port via the PORT environment variable. Never hard-code a port number such as app.listen(3000). Always use process.env.PORT || 3000.
Running npm install via SSH
After uploading your files, connect via SSH to install dependencies:
# SSH into your hosting
ssh [email protected]
# Navigate to your project directory
cd ~/domains/api.yourdomain.com/public_html/
# Install production dependencies
npm install --production
# Verify node_modules was created
ls -la node_modules/ | head -10
Once npm install completes, Phusion Passenger will detect the changes and restart the app automatically. Test by visiting the domain URL in your browser.
Manually Restarting the App
To force-restart the app after code changes, touch the tmp/restart.txt file:
mkdir -p tmp
touch tmp/restart.txt
Passenger detects this file and restarts the Node.js process automatically.
Hosting vs VPS for Node.js: Comparison
| Factor | Shared Hosting (DirectAdmin) | VPS |
|---|---|---|
| Starting price | ~199 THB/month | ~500 THB/month |
| Node.js install | Phusion Passenger (easy) | Self-install via apt/nvm (flexible) |
| Process manager | Passenger handles automatically | PM2 / systemd (manual setup) |
| Node.js version | Limited by hosting provider | Any version via nvm |
| RAM | Shared with other users | Dedicated allocation |
| Best for | Small APIs, test apps, MVPs | Production, high traffic |
| SSH access | Yes (restricted permissions) | Yes (root access) |
Troubleshooting Common Issues
500 Error After Deployment
Common causes: node_modules not installed yet, or the entry file path is wrong. Check:
- Did you run
npm install? - Does the filename in
PassengerStartupFilematch your actual entry file? - Check passenger error log at
~/domains/domain.com/logs/passenger.log
App Does Not Restart After Code Changes
Passenger caches the binary. Force a restart by running:
touch ~/domains/yourdomain.com/public_html/tmp/restart.txt
npm install Fails Due to Permissions
If you see a permission error, verify your SSH user has write access to that directory, or try:
npm install --prefix ~/.npm-packages
Environment Variables Not Working
On shared hosting, create a .env file in the project root and load it with the dotenv package:
npm install dotenv
# In app.js, first line:
require('dotenv').config();
Frequently Asked Questions
node -v command.tmp/restart.txt inside your project directory. Phusion Passenger detects this file and automatically restarts the Node.js process.Shared hosting with Phusion Passenger is a cost-effective option for small Node.js apps and MVPs. If you need to scale or run full Next.js SSR, consider an AsiaGB VPS starting at 500 THB/month with SSD storage and 99% uptime.