Teral
Frameworks

Node.js

Deploy Express, Fastify, Hono, NestJS and other Node.js servers.

Teral recognizes a Node.js project by its package.json. It installs dependencies with npm, pnpm, Yarn or Bun, depending on the lockfile, and runs your build script if there is one.

How the start command is chosen

In this order:

  1. a start script in package.json
  2. the file named in main in package.json
  3. an index.js or index.ts at the root

To start something else, set Command in the app's settings.

Listen on the right port

Read the port from PORT:

import express from "express";

const app = express();
app.get("/health", (_req, res) => res.send("ok"));

const port = Number(process.env.PORT ?? 8080);
app.listen(port, () => console.log(`listening on ${port}`));

Some frameworks listen on localhost by default, which can't be reached from outside the instance. Bind to 0.0.0.0 in that case, for example fastify.listen({ port, host: "0.0.0.0" }).

Shut down cleanly

Teral sends SIGTERM before it stops an instance, then waits 30 seconds. Close the server so requests in progress can finish:

const server = app.listen(port);
process.on("SIGTERM", () => server.close(() => process.exit(0)));

Versions

Pin the Node version with engines in package.json or an .nvmrc file. Pin the package manager with the packageManager field, such as "packageManager": "pnpm@9.15.0".

Edit on GitHub

On this page