This guide applies to instances provisioned with the Node.js blueprint, which comes with Node.js, npm, and PM2 pre-installed via Bitnami.
Accessing Your Server
SSH into your instance:
ssh -i your-key.pem bitnami@YOUR-IP
Verify Node.js is installed:
node --version
npm --version
pm2 --version
Deploying Your Application
Step 1: Upload Your Code
Option A — Git clone:
cd /home/bitnami
git clone https://github.com/your/repo.git myapp
Option B — SCP/SFTP:
scp -i your-key.pem -r ./myapp bitnami@YOUR-IP:/home/bitnami/myapp
Step 2: Install Dependencies
cd myapp
npm install --production
Step 3: Configure Environment Variables
Create a .env file or set environment variables:
nano .env
Add your variables:
PORT=3000
DATABASE_URL=postgresql://...
NODE_ENV=production
Step 4: Start with PM2
pm2 start server.js --name myapp
pm2 save
pm2 startup
PM2 ensures your app restarts if it crashes or the server reboots.
PM2 Management Commands
pm2 list — View running processes
pm2 logs myapp — View application logs
pm2 restart myapp — Restart the app
pm2 stop myapp — Stop the app
pm2 delete myapp — Remove from PM2
pm2 monit — Real-time monitoring dashboard
Setting Up Nginx as Reverse Proxy
For production, put Nginx in front of Node.js:
sudo apt install nginx
sudo nano /etc/nginx/sites-available/myapp
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:3000;
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;
}
}
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Installing SSL with Certbot
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
Certbot auto-configures Nginx and sets up auto-renewal.
Running Next.js or Nuxt.js
npm run build
pm2 start npm --name nextapp -- start