Black Friday: 40% off for life · BLACKFRIDAY40Claim →
crabsmith Get started
Browse documentation
← All documentation

Node.js

On this page

Run any Node.js server—Express, Fastify, Hono, NestJS, or plain node:http—behind Caddy with automatic HTTPS.

Required services

On your server's Services tab, install Caddy and Node.js. Add pnpm if your project uses it.

Prepare your app

Make sure your server reads the PORT environment variable, binds to 127.0.0.1, and has a start script in package.json:

js
import { createServer } from 'node:http';

const port = Number(process.env.PORT || 3000);
createServer((req, res) => res.end('ok')).listen(port, '127.0.0.1');

Create the site

  1. Open your server's Sites tab, click New site, and choose Node.js.
  2. Follow the App → Code → Domain → Run steps: pick your repository and branch, enter your domain (or Free domain), and review your start command on the Run step.
  3. On Run, Run the app as a daemon is enabled by default (PORT=<port> npm start), and Crabsmith adds its restart command to your deploy script automatically.
  4. Click Create site.

Deploy script (JavaScript vs. TypeScript)

  • Plain JavaScript: the default deploy script installs production dependencies and restarts the daemon (commit package-lock.json):
sh
npm ci --omit=dev
sudo systemctl try-restart crabsmith-daemon-<id>
  • TypeScript or compiled apps: because tsc or your bundler is usually in devDependencies, update Settings → Deployment to install dev dependencies and build before restarting the daemon:
sh
npm ci
npm run build
sudo systemctl try-restart crabsmith-daemon-<id>

(Using pnpm? Replace npm ci with pnpm install --frozen-lockfile and npm run build with pnpm run build.)

Environment variables and processes

  • Edit your site's .env file on the Environment tab. Node doesn't load .env automatically—load it in your app or start Node with node --env-file=.env server.js.
  • Check the running daemon and its logs anytime under Processes. (If you turned off Run the app as a daemon during setup, create a daemon there with PORT=<your-site-port> node server.js and paste its restart line into Settings → Deployment.)