Scrawn LogoScrawn Docs
Scrawn LogoScrawn Docs

Backend Deployment

Deploy your Scrawn backend locally or to production

This guide covers running Scrawn backend locally for development and deploying it to production.

Running Locally

Perfect for development and testing before deploying to production.

Start the Server

bun run dev:backend
npm run dev:backend
yarn dev:backend

You should see:

Server listening on http://localhost:8069

When running locally, configure your SDK with:

const scrawn = new Scrawn({
  apiKey: process.env.SCRAWN_KEY,
  baseURL: 'http://localhost:8069',
});

Development Mode

The dev:backend command runs with hot-reload enabled. Any code changes will automatically restart the server.

Production Deployment

Requirements

Before deploying, ensure you have:

  1. A Node.js/Bun runtime environment (Node 18+ or Bun 1.0+)

  2. Required Environment Variables:

    HMAC_SECRET=your_hmac_secret_here
    DATABASE_URL=your_database_url_here
    LEMON_SQUEEZY_API_KEY=your_api_key
    LEMON_SQUEEZY_STORE_ID=your_store_id
    LEMON_SQUEEZY_VARIANT_ID=your_variant_id
  3. Build Command:

    bun install
    npm install
    yarn install
  4. Start Command:

    bun run start
    npm run start
    yarn start

Deployment Options

Scrawn backend can be deployed to any platform that supports Node.js/Bun applications:

  • Platform as a Service (PaaS): Railway, Render, Fly.io, Heroku, etc.
  • Container Platforms: Docker, Kubernetes, AWS ECS, Google Cloud Run
  • VPS/Dedicated Servers: DigitalOcean, Linode, AWS EC2, etc.

Most platforms will automatically detect the start command from your package.json. If not, use bun run start or npm run start.

Port Configuration

Scrawn backend runs on port 8069 by default. Some platforms require you to use a specific port via the PORT environment variable. The server will automatically use process.env.PORT if available.

For production deployments on a VPS or dedicated server, you should use a reverse proxy like Nginx or Caddy. This provides:

  • SSL/TLS termination for HTTPS
  • Better security by hiding your backend port
  • Load balancing capabilities
  • Caching and compression

Example Nginx Configuration:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:8069;
        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;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Example Caddy Configuration:

your-domain.com {
    reverse_proxy localhost:8069
}

Why Reverse Proxy?

A reverse proxy handles SSL certificates, improves security, and lets you serve multiple apps from one server. It's the standard approach for production Node.js deployments.

Understanding Base URLs

The baseURL in your SDK configuration depends on how you've deployed:

Development (Local)

baseURL: 'http://localhost:8069'
baseURL: 'https://your-domain.com'  // Your domain with SSL

Production on PaaS (Railway, Render, etc.)

baseURL: 'https://your-app.platform-domain.com'  // URL provided by platform
baseURL: 'http://your-server-ip:8069'  // ⚠️ Only for testing

Always Use HTTPS in Production

Never expose your backend directly on HTTP in production. Always use HTTPS via a reverse proxy or platform SSL.

Verifying Deployment

After deployment, verify your backend is working:

import { Scrawn } from '@scrawn/core';

const scrawn = new Scrawn({
  apiKey: process.env.SCRAWN_KEY,
  baseURL: 'https://your-base-url',
});

try {
  const result = await scrawn.createCheckoutLink({
    userId: 'test-user-id',
  });
  console.log('✅ Backend is working!', result);
} catch (error) {
  console.error('❌ Backend error:', error);
}

Troubleshooting

Connection Issues

  • Verify the backend is running and accessible
  • Check if port 8069 is open (or your custom port)
  • Ensure firewall rules allow traffic
  • Verify reverse proxy configuration if applicable

Environment Variables

  • Double-check all required variables are set
  • Restart the server after adding/changing variables
  • On PaaS platforms, check the dashboard for environment settings

Database Connection

  • Verify your DATABASE_URL is correct
  • Ensure your database allows connections from your server's IP
  • Check SSL configuration for cloud databases

Next Steps