🚀 Part 4 — Deploying the Node.js Backend on Oracle Cloud (OCI)
In the previous parts, we created our Oracle Cloud account, set up compute instances, and configured networking.
Now, it’s time to bring your Node.js backend to life — deploying it securely and efficiently on your OCI instance.
This guide will cover every step — from uploading code to serving your backend via NGINX — so your API is accessible globally.
🧩 Overview
A Node.js backend (often using Express.js) is the backbone of any full-stack application.
On Oracle Cloud Infrastructure (OCI), we’ll host it inside the compute instance you created earlier.
By the end of this part, you’ll have:
- A live Node.js API running on OCI
- Managed with PM2 for automatic restarts
- Secured and served via NGINX reverse proxy
- Accessible through your server’s public IP or custom domain
⚙️ Step 1: Connect to Your Oracle Instance
Use SSH to connect to your running compute instance:
ssh -i ~/Downloads/oci-key.pem ubuntu@<your-public-ip>Example:
ssh -i ~/Downloads/oci-key.pem ubuntu@132.226.xxx.xxxIf you see a terminal prompt like this:
ubuntu@node-server:~$you’re connected successfully.
📁 Step 2: Install Git and Clone Your Node.js Project
If your code is on GitHub, clone it directly into your instance:
sudo apt install git -y
git clone https://github.com/your-username/your-node-backend.git
cd your-node-backendIf you’re deploying a local project, you can upload files via SCP:
scp -i ~/Downloads/oci-key.pem -r ./your-node-app ubuntu@132.226.xxx.xxx:/home/ubuntu/
🧰 Step 3: Install Node.js (if not already)
Make sure Node.js and NPM are available:
node -v
npm -vIf not, install them:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs🧱 Step 4: Install Dependencies
Go to your project directory and install all required npm packages:
cd your-node-backend
npm installThis downloads all dependencies from package.json.
🔒 Step 5: Set Environment Variables
Create a .env file to store sensitive configuration like database credentials or API keys.
Example .env:
PORT=5000
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/db
JWT_SECRET=mysecurekeyEnsure .env is ignored in .gitignore:
node_modules/
.envYou can also export variables directly:
export PORT=5000
export NODE_ENV=production🧠 Step 6: Run the Node.js Server Manually (for testing)
Try running your app to make sure everything works:
node index.jsor
npm startIf your terminal shows:
Server running on port 5000— that’s a good sign!
Now open your browser:
http://<your-public-ip>:5000If you see your API or “Hello World”, your backend is working fine.
🔁 Step 7: Install PM2 for Background Process Management
We’ll use PM2 to keep your Node.js app running in the background (even after closing SSH).
Install PM2 globally:
sudo npm install pm2 -gStart your app using PM2:
pm2 start index.js --name "node-backend"To make PM2 auto-start on reboot:
pm2 startup systemd
pm2 saveCheck your running processes:
pm2 listNow your backend runs 24/7, even if the SSH session ends.
Step 8: Configure NGINX Reverse Proxy
By default, Node.js runs on port 5000 (or custom port).
We’ll configure NGINX to route public HTTP requests (port 80) to your backend.
Open NGINX configuration:
sudo nano /etc/nginx/sites-available/defaultReplace the contents with:
server { listen 80; server_name _; location / { proxy_pass http://127.0.0.1:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }Test and restart NGINX:
sudo nginx -t sudo systemctl restart nginx
Now your backend is accessible at:
http://<your-public-ip>/without the need to specify port 5000.
🔐 Step 9: Optional — Secure with HTTPS (SSL)
To secure your Node.js app, install Certbot for free SSL via Let’s Encrypt:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginxFollow the prompts and select your domain to enable HTTPS.
🧪 Step 10: Test Everything
- Visit
http://<public-ip>→ should load your Node.js API - Run
pm2 list→ app should be running Check NGINX logs:
sudo tail -f /var/log/nginx/access.log
Next Step (Coming Part 5)
In Part 5, we’ll deploy your React.js frontend on the same OCI instance, build it for production, and configure NGINX to serve both frontend + backend together.
🏁 Summary
In this part, we:
- Deployed a Node.js backend on Oracle Cloud.
- Configured PM2 for continuous uptime.
- Set up NGINX as a reverse proxy.
- (Optionally) Secured the app with SSL.
You now have a fully running backend API hosted on Oracle Cloud — stable, scalable, and production-ready.
