NEW RELEASEDownload the n8n Starter Pack (5 Workflows + Docker Setup) for free — or save 20% on Pro Kits with DEVHUB20.
DevHubTools Robot Mascot
DevHubTools
Back to All Tutorials & Reviews
Cloud & DevOps Tutorials11 min readAvnish Yadav (7+ Yrs Salesforce & Full-Stack Dev)

How to Deploy a Node.js App on AWS (Step-by-Step Production Guide + Docker Setup)

Learn how to containerize a production Node.js API, configure Nginx + SSL, and deploy with zero downtime on AWS ECS/EC2 — or launch in 3 minutes on DigitalOcean.

Featured yaml Implementation
# .github/workflows/deploy-aws.yml — Automated Production Pipeline
name: Deploy Node.js to AWS ECS
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      - name: Build, Tag, and Push Image to Amazon ECR
        run: |
          docker build -t devhub-node-api:latest .
          docker tag devhub-node-api:latest ${{ secrets.ECR_REGISTRY }}/devhub-node-api:latest
          docker push ${{ secrets.ECR_REGISTRY }}/devhub-node-api:latest

Stop Deploying Node.js with Manual SSH & `git pull`

Running `ssh ubuntu@ip` and manually restarting PM2 works for a weekend hackathon, but the first time traffic spikes or an environment variable goes missing, your app goes down.

In this step-by-step tutorial, we'll build a **production-hardened Node.js deployment pipeline** using Docker, health checks, and automated CI/CD.


Step 1: Add a Health Check Endpoint in Node.js Every load balancer (AWS ALB or DigitalOcean App Platform) needs a deterministic health check route that verifies database connectivity before routing traffic:

```typescript app.get("/api/health", async (_req, res) => { return res.status(200).json({ status: "ok", uptime: process.uptime(), timestamp: new Date().toISOString(), }); }); ```

Step 2: Multi-Stage Dockerfile for Minimal Attack Surface Never ship `devDependencies` or uncompiled source files to production. Use `node:20-alpine` with a non-root user to keep your image under 120MB.

Step 3: Choosing Between AWS and DigitalOcean - **Choose AWS (EC2 / ECS Fargate)** when you need enterprise VPC isolation, IAM role-based permissions, S3/SQS event pipelines, or **AWS Activate startup credits**. - **Choose DigitalOcean** when you want predictable `$4–$12/month` flat pricing, instant GitHub-to-App-Platform deploys in 180 seconds, and `$200` in free starter credits.

Companion Cheat Sheet & Code Pack

Free Download: AWS DevOps & Docker Deployment Checklist (PDF + CLI Commands)

Instant Markdown + PDF download plus a 20% discount code (DEVHUB20) for our Digital Store.

Recommended Tools Mentioned in This Tutorial

Cloud Services4.9

DigitalOcean

$200 Free Credit + $100 Referral Tier

Claim Partner Deal
Cloud Services4.8

AWS Cloud & AWS Activate

Startup Credits + Free Tier

Claim Partner Deal
Online Courses4.7

Udemy Tech Courses

Up to 85% Off Flash Deals

Claim Partner Deal