</>
Skip to content
Node.js lessons (44/44)

Node.js — Deployment

Deployment Options

PlatformType
HerokuPaaS
AWSIaaS/PaaS
DigitalOceanVPS
RailwayPaaS
VercelServerless

Heroku

# Create Procfile
echo "web: node app.js" > Procfile

# Deploy
git init
git add .
git commit -m "Initial commit"
heroku create
git push heroku main

Docker

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "app.js"]
docker build -t myapp .
docker run -p 3000:3000 myapp

PM2 Process Manager

npm install -g pm2
pm2 start app.js
pm2 save
pm2 startup

Production Settings

// Use environment variables
const port = process.env.PORT || 3000;

// Enable compression
const compression = require('compression');
app.use(compression());

// Trust proxy
app.set('trust proxy', 1);

Mini Practice

  1. Deploy to Heroku
  2. Create a Dockerfile
  3. Use PM2 for process management
  4. Configure production settings

Up Next

Congratulations! You've completed the Node.js course.

Related Topics

Frequently Asked Questions about Deployment

What is Deployment in Node.js?

Deployment is a fundamental concept in Node.js. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Deployment?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Deployment.

Why is Deployment important in Node.js?

Deployment is essential for Node.js development. Understanding this concept will help you write better code and solve real-world problems more effectively.