Documentation

Instant Express is a JSON-configured Express server. Define routes, auth, CRUD, and custom handlers in one config file — ship a REST API without boilerplate.

Install

npm install express-instant

Requires Node.js 18+.

Quick start

CLI

cp slices.example.json my-api.json
cp .env.example .env
npx express-instant --config-file my-api.json

Library

import { createApp, loadConfigFromFile } from "express-instant";

const config = loadConfigFromFile("./my-api.json");
const app = await createApp(config);
app.listen(3000);

Add to package.json: "start": "express-instant --config-file my-api.json"

Config file

Top-level options:

KeyTypeDescription
portnumberListen port (default 3000)
dotenvbooleanLoad .env on startup
corsboolean | objectEnable CORS (pass options to cors)
mongoDBbooleanConnect MongoDB via MONGODB_STRING
bodyParserobject{ "json": true, "urlencoded": { "extended": true } }
routesobjectPath → HTTP method → handler config
websocketsobjectPath → WebSocket template config

Example — Todo API with auth

{
  "port": 3000,
  "dotenv": true,
  "cors": true,
  "mongoDB": true,
  "bodyParser": { "json": true },
  "routes": {
    "/health": {
      "GET": { "type": "template", "template": "health" }
    },
    "/auth/sign-up": {
      "POST": { "type": "template", "template": "signUp" }
    },
    "/auth/sign-in": {
      "POST": { "type": "template", "template": "signIn" }
    },
    "/items/:collection": {
      "GET": { "type": "template", "template": "listItems" },
      "POST": {
        "type": "template",
        "template": "listItems",
        "middleware": ["requireAuth"]
      }
    }
  }
}

See slices.example.json for a full copy-paste example.

Route types

TypeDescription
templateBuilt-in handler (health, signUp, …)
functionInline handler body as a string
moduleLoad a local .js module from disk
importImport an ES module handler
staticServe static files from a directory
routesNested router (sub-routes)

Middleware on routes

{
  "POST": {
    "type": "template",
    "template": "listItems",
    "middleware": ["requireAuth"]
  }
}

Built-in templates

TemplateDescription
health{ success, status, uptime }
signUpRegister user → MongoDB + bcrypt + JWT
signInLogin → JWT
listItemsIn-memory CRUD on /items/:collection
mongoItemsMongoDB CRUD on /db/:collection (requires mongoDB: true)

Built-in middleware

NameDescription
requireAuthValidates Authorization: Bearer <jwt>

WebSockets

{
  "websockets": {
    "/ws": { "template": "echo" }
  }
}

Built-in echo template sends { "type": "connected" } on connect and echoes messages back.

Extend the library

import { registerTemplate, registerMiddleware } from "express-instant";

registerTemplate("myHandler", (req, res) => res.json({ ok: true }));
registerMiddleware("adminOnly", (req, res, next) => { /* ... */ next(); });

Environment variables

MONGODB_STRING=mongodb://localhost:27017
MONGODB_NAME=express-instant
JWT_SECRET=change-me-in-production
EXPRESS_INSTANT_CONFIG=./my-api.json
PORT=3000

Live API demo

This site runs Instant Express on Vercel. Try the health endpoint:

curl https://express-instant.vercel.app/api/health

Open /api/health in your browser.