codex-lv4-may-2025

╔═══════════════════════════════════════════════════════════════╗
║                                                               ║
║    ☁️   Deploy to DigitalOcean  ☁️                           ║
║                                                               ║
║    ┌─────────────────────────────────┐                       ║
║    │ $ ssh root@your-droplet-ip     │                       ║
║    │ $ nvm install node             │                       ║
║    │ $ git clone your-repo          │                       ║
║    │ $ npm install                  │                       ║
║    │ $ pm2 start app.js             │                       ║
║    └─────────────────────────────────┘                       ║
║                                                               ║
║           Get your app running in the cloud! 🚀            ║
║                                                               ║
╚═══════════════════════════════════════════════════════════════╝

Deploy Your App to DigitalOcean

This guide will walk you through deploying your Node.js application to DigitalOcean. For a detailed video walkthrough, check out this tutorial: DigitalOcean Deployment Tutorial

Quick Start Guide

1. Create a Droplet

2. Access the Console

3. Install Node.js via NVM

Once you’re in the console, install Node Version Manager (nvm) and Node.js:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install node
nvm use node

Verify the installation:

node --version
npm --version

4. Clone Your Project

Move to /var/www directory - this is the conventional location for web applications on Linux servers:

cd /var/www

Clone your project repository:

git clone https://github.com/your-username/your-repo.git
cd your-repo
npm install

5. Run and Test Your Project

Start your application:

npm run start

Test that it’s working by visiting http://your-droplet-ip:PORT in your browser.

6. Set Environment Variables

Set your environment variables, including the PORT. See the Environment Variables Guide for details.

You can set them temporarily:

export PORT=3000
export DATABASE_URL=your-database-url
export API_KEY=your-api-key

Or add them to ~/.bashrc for persistence:

echo 'export PORT=3000' >> ~/.bashrc
echo 'export DATABASE_URL=your-database-url' >> ~/.bashrc
source ~/.bashrc

Or use a .env file with the dotenv package in your project.

7. Use PM2 to Keep Your App Running

Important: Stop your current process (Ctrl+C) and follow the video tutorial to set up PM2. This will keep your app running even after you log out.

Install PM2:

npm install -g pm2

Start your app with PM2:

pm2 start app.js --name my-app

PM2 commands you’ll need:

Watch the video tutorial for detailed PM2 setup instructions!

8. Bonus: Add a Domain

Once your app is running, you can add a custom domain:

Student Resources