Express Normalize Query Params Middleware
raw JSON → 0.5.1 verified Sat Apr 25 auth: no javascript
Express middleware that normalizes incoming query parameter names to be case-insensitive. Current stable version is 0.5.1, with low release cadence (last update likely pre-2018). Key differentiator: simple array-based whitelist approach, no dependencies, small footprint. Alternative to libraries like 'express-case-sensitive' or manual normalization. Note: only handles case normalization, not type coercion or default values.
Common errors
error TypeError: normalizeQueryParams is not a function ↓
cause Using ES6 import incorrectly with CommonJS require pattern.
fix
Use correct import: import normalizeQueryParams from 'express-normalize-query-params-middleware' or const normalizeQueryParams = require('express-normalize-query-params-middleware').default
error Cannot find module 'express-normalize-query-params-middleware' ↓
cause Package not installed or typo in package name.
fix
Run: npm install express-normalize-query-params-middleware
Warnings
gotcha The middleware only normalizes parameter names listed in the whitelist array; any extra params are left unchanged and case-sensitive. ↓
fix Ensure all expected parameters are included in the array passed to normalizeQueryParams.
gotcha The whitelist comparison is case-insensitive, but the result sets the key to the lowercase version of the whitelist entry, not the original incoming key. This may cause unexpected key naming if whitelist has mixed case. ↓
fix Always use lowercase strings in the whitelist to avoid confusion.
gotcha The middleware modifies req.query in place; if other middleware also modifies query, order matters. ↓
fix Place this middleware early in the stack, before any middleware that depends on normalized query params.
Install
npm install express-normalize-query-params-middleware yarn add express-normalize-query-params-middleware pnpm add express-normalize-query-params-middleware Imports
- default wrong
const normalizeQueryParams = require('express-normalize-query-params-middleware').defaultcorrectimport normalizeQueryParams from 'express-normalize-query-params-middleware' - default
const normalizeQueryParams = require('express-normalize-query-params-middleware') - TypeScript types
import normalizeQueryParams from 'express-normalize-query-params-middleware'
Quickstart
import normalizeQueryParams from 'express-normalize-query-params-middleware';
import express from 'express';
const app = express();
const allowedParams = ['name', 'email', 'age'];
app.use(normalizeQueryParams(allowedParams));
app.get('/user', (req, res) => {
// req.query.name, req.query.email, req.query.age are case-insensitive
// e.g., ?Name=John&EMAIL=john@example.com works
res.json(req.query);
});
app.listen(3000);