So you’ve built a TypeScript application, maybe it’s a Node.js backend with Express, or something more custom—and now you’re looking to get it live on DigitalOcean. Since TypeScript compiles down to JavaScript, deploying it isn’t wildly different from a plain Node.js app, but we’ll cover the key tweaks for handling the build process. I’ll walk you through this step by step, focusing on two main paths: using a Droplet (which is like your own virtual server for more control) and the App Platform (their managed service for quicker setups). We’ll also touch on automating deployments to keep things smooth over time. This guide aims to stay useful even as versions evolve—just double-check DigitalOcean’s docs for the latest tweaks on things like Node versions or UI changes.
First off, let’s make sure you’re set up locally. Assuming you’ve got a TypeScript project ready (if not, start with initializing one using npm init
and adding TypeScript via npm install --save-dev typescript @types/node
), you’ll need to compile it to JavaScript before deployment. Add a tsconfig.json
if you haven’t already—something basic like this:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Then, in your package.json
, throw in scripts for building and starting:
"scripts": {
"build": "tsc",
"start": "node dist/index.js"
}
Run npm run build
to generate the dist
folder with your compiled JS. Test it locally with npm start
to ensure everything runs without hiccups. Cool? Alright, onto the deployment options.
Option 1: Deploying to a DigitalOcean Droplet (For Hands-On Control)
Droplets give you a full Ubuntu server to configure as you like—great if you need custom setups or databases on the same machine. Start by signing up for DigitalOcean if you haven’t, and create a Droplet. Go for Ubuntu (latest LTS, like 22.04 or whatever’s current), a basic plan (start with $6/month for 1GB RAM), and add an SSH key for secure access. Once it’s spun up, grab the IP address.
Connect via SSH: Open your terminal and run ssh root@your-droplet-ip
. If you’re on Windows, use PuTTY or the built-in OpenSSH. First things first, update the system:
apt update && apt upgrade -y
Install Node.js. Use Node Version Manager (nvm) for flexibility—curl the install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm install --lts
This grabs the latest LTS version. Verify with node -v
and npm -v
. Now, clone your repo onto the Droplet:
git clone https://github.com/your-username/your-repo.git
cd your-repo
npm install
npm run build
That builds your TypeScript to JS. To keep it running reliably, install PM2—a process manager that restarts your app if it crashes and runs it as a daemon.
npm install -g pm2
pm2 start npm --name "your-app" -- run start
pm2 startup systemd
pm2 save
Follow the output to set it up with systemd so it boots on restarts. Test by killing the process and seeing it come back. Now, for production, you’ll want Nginx as a reverse proxy to handle traffic securely. Install it:
apt install nginx -y
Edit the config at /etc/nginx/sites-available/default
(use nano or vim):
Add or replace the location block like this:
server {
listen 80;
server_name your-domain-or-ip;
location / {
proxy_pass http://localhost:3000; # Change to your app's port
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 the config with nginx -t
, then restart: systemctl restart nginx
. Point your domain to the Droplet’s IP via DNS (use DigitalOcean’s networking tab for that), and boom—your app should be live at http://your-domain. For HTTPS, add Certbot later: apt install certbot python3-certbot-nginx
, run certbot --nginx
, and follow the prompts.
One thing to watch: If your app uses environment variables (like API keys), set them in a .env
file and load with dotenv in your code. On the Droplet, use pm2 start
with --env production
if needed.
Option 2: Deploying to DigitalOcean App Platform (Easier, Managed Hosting)
If you don’t want to manage servers, App Platform is like Heroku but on DigitalOcean— it handles scaling, builds, and deploys from Git. Push to GitHub or GitLab, and it auto-deploys. For TypeScript, ensure your repo has the build script in package.json
as I mentioned earlier, and App Platform will detect it as a Node.js app.
Head to your DigitalOcean dashboard, click “Create” > “Apps.” Connect your GitHub repo (grant access if needed), select the branch (like main), and let it auto-detect the service type— it should pick Node.js. If your app’s in a subfolder (common in monorepos), specify the source dir.
Customize the build command if needed: Set it to npm run build
to compile TypeScript, and run command to npm start
. Add any env vars in the UI. Choose a plan (basic starts free for static sites, but for dynamic apps it’s around $5/month), pick a region close to your users, and launch.
Once deployed, you’ll get a URL like your-app.ondigitalocean.app. Map a custom domain in the settings, and enable HTTPS—it’s automatic. App Platform handles logs, metrics, and auto-scaling if you upgrade. If changes happen, just push to Git, and it rebuilds.
Pro tip: For databases, link a managed one from DigitalOcean right in the app config— no extra setup like on a Droplet.
Automating with GitHub Actions (For CI/CD)
To make this low-maintenance, set up CI/CD. This way, pushes to main auto-deploy without manual SSH. For Droplets, use GitHub Actions to SSH in and pull changes.
In your repo, create .github/workflows/deploy.yml
:
name: Deploy to DigitalOcean
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to Droplet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_IP }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.SSH_PASSWORD }}
script: |
cd /path/to/your/repo
git pull origin main
npm install
npm run build
pm2 reload your-app
Add secrets in GitHub repo settings: DROPLET_IP, SSH_USER (like root), SSH_PASSWORD. For key-based auth, use SSH_KEY instead. Push, and watch it deploy automatically.
For App Platform, it’s even simpler—link your repo, enable auto-deploys, and GitHub handles the rest without extra YAML.
Best practices for longevity
Monitor your app with DigitalOcean’s built-in tools or add something like New Relic. Scale by upgrading your Droplet or using App Platform’s horizontal scaling. Back up your code and data regularly—Droplets have snapshots, App Platform has auto-backups on pro plans. If your app grows, consider Kubernetes on DigitalOcean, but start simple.
There you have it—a solid path from local to live. If something’s not clicking, leave a comment explaining your issue and let’s see if we can’t find a solution together.