Skip to main content

Installation

npm install keyport-express

Setup and usage

1

Import the middleware

Import keyportLicense from keyport-express alongside your Express app:
import express from 'express';
import { keyportLicense } from 'keyport-express';

const app = express();
2

Apply the middleware to a route group

Mount keyportLicense with app.use to protect any path. Supply your API key directly or point to a config file:
app.use('/api', keyportLicense({
  apiKey: process.env.KEYPORT_API_KEY!,
}));
All routes mounted under the path you pass to app.use will require a valid license key before the request is forwarded.
The middleware validates the incoming license key against POST /api/v1/validate on each request. Requests that fail validation receive an error response before reaching your route handlers.
Load your API key from an environment variable (process.env.KEYPORT_API_KEY) rather than embedding it in source code.