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:
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
- Open your server's Sites tab, click New site, and choose Node.js.
- 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.
- 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. - 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):
npm ci --omit=dev
sudo systemctl try-restart crabsmith-daemon-<id>- TypeScript or compiled apps: because
tscor your bundler is usually indevDependencies, update Settings → Deployment to install dev dependencies and build before restarting the daemon:
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
.envfile on the Environment tab. Node doesn't load.envautomatically—load it in your app or start Node withnode --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.jsand paste its restart line into Settings → Deployment.)