Skip to content

Deploy Express

Stackpad auto-detects Express applications and deploys them as Node.js servers.

Quick deploy

  1. Push your Express project to GitHub
  2. Create a new project on Stackpad and select your repo
  3. Stackpad detects express in your dependencies
  4. Your API is live at your-project.your-org.stackpad.eu

Configuration

Make sure your app reads the port from the environment:

import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});

Your package.json should have a start script:

{
"scripts": {
"build": "tsc",
"start": "node dist/index.js"
}
}

TypeScript

If you’re using TypeScript, make sure tsc runs during the build step. Stackpad runs your build script before start.

Health checks

Stackpad’s health check sends a GET request to your configured port. Make sure your root route (or any route) returns a 2xx response. If your API doesn’t have a root route, add one:

app.get('/', (req, res) => {
res.status(200).json({ ok: true });
});

Database

Add PostgreSQL to your project and redeploy:

import { Pool } from 'pg';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
app.get('/users', async (req, res) => {
const result = await pool.query('SELECT * FROM users');
res.json(result.rows);
});

What’s next?