# Express

An Express 4 REST API starter for Node.js 22 in plain JavaScript, for developers who want a small, tested skeleton to add their own routes to. It includes CORS, JSON body parsing, a /health check, JSON 404 and 500 responses and node:test tests, with no database and no build step.

- Framework: Express (JavaScript)
- Category: Starters / REST APIs
- Creates: a server app
- Plan: Free
- Price: Free
- Author: Light Cloud
- Page: https://templates.light-cloud.com/starters/rest-apis/express-api-starter
- Updated: 2026-11-21

## Features

- GET / lists the endpoints and GET /health returns status, an ISO timestamp and process uptime
- CORS open to every origin through the cors middleware, ready to narrow to your own domain
- A malformed JSON body answers 400 in JSON instead of Express's HTML error page
- Unknown routes answer 404 as { "error": "Not found" }; unexpected errors answer 500 in JSON and are logged
- src/app.js builds the app and src/server.js starts it, so tests listen on a random free port
- Graceful shutdown on SIGTERM and SIGINT lets in-flight requests finish before the process exits
- Four tests with the built-in node --test runner and fetch, no test libraries to install
- Two runtime dependencies, express and cors; listens on PORT, defaulting to 8080

## What you need

- Free plan: it runs as a server app, and the Free plan includes 3 server apps
- To run it locally: Node.js 22 or newer and npm
- No API keys: it starts with nothing to configure

## About

The app is plain CommonJS JavaScript that npm start runs directly, with configuration read once in src/config.js and errors handled by two middleware functions in src/middleware/errors.js. Keeping the app and the server in separate files is what lets the tests start it on port 0 and call it with fetch. The first things to change are the CORS origin in src/app.js and the routes in src/routes/index.js, where new routers mount before the 404 handler. On Light Cloud it runs npm start in a container on the PORT the platform sets, and every push to your copy redeploys it.

## Questions

### Is there a free Express API starter template?

Yes. This Express 4 starter is MIT licensed and free to copy from GitHub, and it fits within Light Cloud's Free plan, which includes 3 server apps with no card needed.

### How do I add a new route in Express?

Add a handler to src/routes/index.js, or create a router file in src/routes/ and mount it in src/app.js with app.use('/things', thingsRouter). Mount it before the notFound handler so it is reached.

### How do I restrict CORS to my own domain in Express?

The starter calls app.use(cors()), which allows every origin. Pass your origins instead, for example app.use(cors({ origin: 'https://example.com' })).

### Does this Express starter use TypeScript?

No. It is plain JavaScript with no build step. If you want TypeScript, the NestJS API starter is the typed option in the same gallery.

### Can I host this Express API without Light Cloud?

Yes. It contains no Light Cloud code: any host with Node.js 22 runs it with npm ci --omit=dev and npm start, with PORT set.
