Gatelin-express.js is an open source Gatelin gateway toolset for Express.js.
- 🪶 Very lightweight
- 🧪 Thoroughly tested
- 🚚 Shipped as ECMAScript Express module
- 📝 Written in TypeScript
- node: 22
This is the oldest targeted version.
$ npm i @dwtechs/gatelin-express// @ts-check
import express from "express";
const router = express.Router();
import getConsumer from "@dwtechs/gatelin-express";
// Routes
// Get users and returns Json
router.get("/search", getConsumer, ...);
// Add new users
router.post("/", getConsumer, ...);The getConsumer middleware extracts and validates consumer information from request headers.
It stores the validated consumer information in res.locals.consumerId and res.locals.consumerName for use by subsequent middleware in the request pipeline.
It must be called whenever the route is protected and requires consumer information.
/**
* Middleware to extract and validate consumer information from request headers.
* Retrieves consumer ID from 'x-consumer-id' header and consumer name from 'x-consumer-name' header.
* Validates that the ID is a valid number between 1 and 999999999, and the name has at least 5 characters.
* Stores the validated consumer information in res.locals.consumerId and res.locals.consumerName
* for use by subsequent middleware in the request pipeline.
*
* @param {Request} req - The Express request object containing consumer headers (x-consumer-id and x-consumer-name).
* @param {Response} res - The Express response object where consumer data will be stored in res.locals.
* @param {NextFunction} next - The next middleware function in the Express.js request-response cycle.
*
* @returns {void} Calls the next middleware function with an error if consumer validation fails,
* otherwise proceeds to the next middleware function.
*
*/
function getConsumer(req: Request, res: Response, next: NextFunction): void {}
Gatelin-express.js uses @dwtechs/Winstan library for logging. All logs are in debug mode. Meaning they should not appear in production mode.
Gatelin-express.js is still in development and we would be glad to get all the help you can provide. To contribute please read contributor.md for detailed installation guide.
| Purpose | Choice | Motivation |
|---|---|---|
| repository | Github | hosting for software development version control using Git |
| package manager | npm | default node.js package manager |
| language | TypeScript | static type checking along with the latest ECMAScript features |
| module bundler | Rollup | advanced module bundler for ES6 modules |
| unit testing | Jest | delightful testing with a focus on simplicity |