Skip to content
For agents
Browse guides

Express

Deploy an Express HTTP API or server-rendered application.

Open Markdown

Deploy an Express API or web app.

Server entry point

This guide assumes your server starts from server.js. With TypeScript, compile first and start the compiled file, such as dist/server.js.

JavaScript
app.get("/health", (_req, res) => res.status(200).send("ok"));
app.listen(Number(process.env.PORT ?? 3000), "0.0.0.0");

Set the app's health path to /health.

Your app sits behind Smolcloud's proxy. If it reads the visitor's IP or sets secure cookies, configure Express's trust proxy. Give it a specific hop count or address rather than true, which trusts headers anyone can send.

Build with a Dockerfile

This Dockerfile uses npm. For pnpm, Yarn or Bun, copy that tool's lockfile instead and change the install line.

Code
FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20 AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm prune --omit=dev

FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20
WORKDIR /app
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000
COPY --from=build --chown=10001:10001 /app ./
USER 10001:10001
EXPOSE 3000
CMD ["node", "server.js"]

Deploy the app

Save the Dockerfile at the source root. In Configuration, set the port to 3000 and the health path to the route you added above. Add a .dockerignore that excludes .env*, .git, node_modules and local build output, then deploy:

Shell
smolcloud deploy APP_ID .

Open the address it prints. You can also call a route from the CLI:

Shell
smolcloud request APP_ID /

You don't have to write a Dockerfile: see Automatic builds. To add a database or file storage, see Databases and files.

See also: Express production guidance.