Skip to content

Express API setup

Use @monque/management-express to inspect and manage jobs over HTTP from your Express application. It includes the Management routes and an OpenAPI document.

For the browser dashboard, follow Dashboard setup.

bun add @monque/management-express @monque/management @monque/core express mongodb

Requires Node.js 22.12 or newer and Express 5.2.1 or newer within version 5.

Reuse your application’s initialized Monque instance:

import { createManagementExpressRouter } from "@monque/management-express";

app.use("/ops", createManagementExpressRouter({ monque }));

The API is available under /ops/api/v1, with OpenAPI JSON at /ops/openapi.json. The router does not initialize or start the scheduler. See the Quick Start if you have not configured Monque yet.

Mount your application’s authentication middleware before the router. It should reject unauthenticated requests and make the authenticated principal available to later middleware. For example, if it sets res.locals.operator:

app.use("/ops", requireOperator);
app.use(
  "/ops",
  createManagementExpressRouter<{ canManageJobs: boolean }>({
    monque,
    context: ({ res }) => ({
      canManageJobs: res.locals.operator.canManageJobs === true,
    }),
    authorize: ({ action, context }) => action === "read" || context.canManageJobs,
  }),
);

requireOperator and the principal stored in res.locals belong to your application. Do not treat a user ID supplied in an HTTP header as authenticated identity. The middleware also protects the OpenAPI document.

The context callback can return a value or a promise. The value is available to authorize, serializePayload, and serializePayloadByJobName. See Management authorization for permission details.

Browser mutations use the Management handler’s origin protection. Same-origin Dashboard requests work by default; pass trustedOrigins: ["https://dashboard.example.com"] to allow a separate Dashboard origin. Express constructs the request URL from req.protocol and the Host header. Behind a reverse proxy, preserve the public host and configure Express proxy trust for the public protocol, or explicitly trust the public Dashboard origin.

Customize the document path and the public server URL:

app.use(
  "/internal/management",
  createManagementExpressRouter({
    monque,
    openApi: {
      path: "/docs/openapi.json",
      serverUrl: "https://ops.example.com/internal/management",
    },
  }),
);

This serves the document at /internal/management/docs/openapi.json. Set serverUrl to the public Management mount URL when a reverse proxy changes the externally visible address. By default it uses the Express mount path.

Set openApi: false to disable this route. The JSON document can be used with OpenAPI client generators or an API documentation viewer of your choice.

The router accepts Management options, including readOnly, authorize, payload serializers, and parallelCapabilityChecks, plus context and openApi.

See ManagementExpressRouterOptions for the full type reference.