Skip to Content

Deploy Express.js

1. Initialize

cd my-express-app espacetech init
espacetech.json
{ "name": "my-express-app", "framework": "express", "build_command": "npm install", "start_command": "node index.js", "port": 3000 }

2. Listen on the Correct Port

Ensure your app reads the PORT environment variable:

index.js
const express = require("express"); const app = express(); const PORT = process.env.PORT || 3000; app.get("/", (req, res) => { res.json({ message: "Hello from Espace-Tech Cloud!" }); }); app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

3. Deploy

espacetech deploy

Using with TypeScript

espacetech.json
{ "name": "my-express-app", "framework": "express", "build_command": "npm run build", "start_command": "node dist/index.js", "port": 3000 }

Add a Database

# Create a PostgreSQL database espacetech db create my-db # Link it to your project (injects DATABASE_URL) espacetech db link my-db --project my-express-app # Redeploy to pick up the new env var espacetech deploy
// Use the injected DATABASE_URL const { Pool } = require("pg"); const pool = new Pool({ connectionString: process.env.DATABASE_URL });

Auth Middleware with SDK

import { EspaceTech } from "@espace-tech/sdk"; const client = new EspaceTech({ apiToken: process.env.ESPACE_TECH_TOKEN! }); app.use("/api", async (req, res, next) => { const token = req.headers.authorization?.replace("Bearer ", ""); if (!token) return res.status(401).json({ error: "Unauthorized" }); const user = await client.auth.verifyToken("auth-app-id", token); if (!user.valid) return res.status(401).json({ error: "Invalid token" }); req.user = user; next(); });