Registry / auth-security / express-maskdata-middleware

express-maskdata-middleware

JSON →
library0.1.1jsnpmunverified

Express middleware for masking sensitive data in API responses, built on maskdata. Version 0.1.1 (latest), stable but early stage. Released irregularly. Differentiates by integrating maskdata into Express with simple rule-based configuration for common fields like email, password, phone, SSN, credit card. Supports TypeScript out of the box. Minimal footprint; only dependency is maskdata. Ideal for protecting PII in response bodies without manual transformation.

npm install express-maskdata-middleware
INSTALL
IMPORT
SIG · EXPRESS-MASKDATA-M
E
express-maskdata-middleware
auth-securityjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createMaskingMiddleware
import { createMaskingMiddleware } from 'express-maskdata-middleware'
const { createMaskingMiddleware } = require('express-maskdata-middleware')
Package exports ESM. For CJS use dynamic import or check compatibility; named export only.
MaskingRules
import type { MaskingRules } from 'express-maskdata-middleware'
import { MaskingRules } from 'express-maskdata-middleware'
MaskingRules is exported as a TypeScript type, not a value. Use type import to avoid runtime errors.
default import
import expressMaskDataMiddleware from 'express-maskdata-middleware'
import * as expressMaskDataMiddleware from 'express-maskdata-middleware'
Package has no default export; only named export createMaskingMiddleware is available. This default import will fail at runtime.

Initializes an Express app, creates masking middleware with rules for email and password, and applies to all routes. The /user endpoint returns JSON with sensitive fields automatically masked.

import express from 'express'; import { createMaskingMiddleware } from 'express-maskdata-middleware'; const app = express(); const maskingRules = { emailFields: ['email'], passwordFields: ['password'], phoneFields: ['phoneNumber'], ssnFields: ['ssn'], cardFields: ['creditCard'], }; app.use(createMaskingMiddleware(maskingRules)); app.get('/user', (req, res) => { res.json({ email: 'user@example.com', password: 'supersecretpassword', username: 'testuser', }); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
gotchaMiddleware only masks JSON responses. Non-JSON responses (e.g., XML, HTML) are not transformed.
fix
Use express.json() and ensure res.json() is used for responses you want masked.
affects: >=0.0.0
gotchaField names in maskingRules must match exact keys in the response object; nested field paths are not supported (e.g., 'user.email' will not match).
fix
Flatten or preprocess nested objects, or use maskdata directly for complex structures.
affects: >=0.0.0
gotchaThe middleware does not mask arrays of objects; only top-level fields and objects at root or immediate children are processed.
fix
Implement custom masking for arrays if needed, or ensure array elements are processed individually.
affects: >=0.0.0
gotchapackage name is misspelled 'express-maskdata-middleware' but actual npm package is 'express-maskdata-middleware' (both correct here; warning for future readers).
fix
Use the exact npm name: `express-maskdata-middleware`.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: createMaskingMiddleware is not a function
Attempting to use default import or wrong named import (e.g., import * as mask).
fix
Use named import: import { createMaskingMiddleware } from 'express-maskdata-middleware'.
Cannot find module 'express-maskdata-middleware'
Package not installed or misspelled.
fix
Run: npm install express-maskdata-middleware --save
Argument of type '{ emailFields: string[]; }' is not assignable to parameter of type 'MaskingRules'
Missing required properties or TypeScript type mismatch; MaskingRules expects all optional fields but error may arise from strict null checks or version mismatch.
fix
Ensure all used fields are defined in the rules object, or use type assertion: createMaskingMiddleware(rules as MaskingRules).
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
maskdatarequiredCore masking engine used by the middleware for all field-level transformations.
expressrequiredPeer dependency required to integrate as middleware in Express applications.
Agent activity
13 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
express-maskdata-middleware — npm install express-maskdata-middleware · libregistry