@naskot/node-express-api-toolkit
v0.1.0
Published
Express API toolkit: hardening, compression, CORS, metrics, rate limiting, flood guard, and logger.
Downloads
58
Maintainers
Readme
@naskot/node-express-api-toolkit
Express-only toolkit extracted from starter-template.
Includes:
- One installer namespace:
install.* install.cors,install.compression,install.hardening,install.rateLimit,install.metrics- Flood/loop guard helpers
- Shared logger
Install
npm i @naskot/node-express-api-toolkitUsage (single install object)
import { configureToolkitConfig, install, logger } from "@naskot/node-express-api-toolkit";
// service-level config injection (no process.env read inside the library)
configureToolkitConfig({
nodeEnv: "development",
logger: {
level: "info",
},
cors: {
enabled: true,
origins: ["*"],
credentials: false,
maxAge: 86400,
},
killSocketMaxHits: 30,
redisCache: {
host: "redis_cache",
port: 6379,
username: "",
password: "",
lazyConnect: true,
maxRetriesPerRequest: null,
enableReadyCheck: true,
},
pm2NodeAppInstance: "0",
});
// matches the starter initializer flow (53 -> 57)
install.hardening(app, {
trustProxy: true,
helmetEnabled: true,
helmetCspEnabled: false,
hppEnabled: true,
poweredBy: "MyApp",
});
install.compression(app, {
enabled: true,
threshold: 1024,
});
install.cors(app, {
preflight: /.*/,
logRules: true,
});
install.rateLimit(app, {
enabled: false,
points: 100,
durationSec: 60,
blockSec: 60,
bypassPaths: ["/", "/health", "/metrics"],
ignoreIps: [],
redisCredentials: null,
redisPoolName: "REDIS_CACHE",
redisKeyPrefix: "{EXPRESS_RATE_LIMITER}",
});
install.metrics(app, {
enabled: true,
path: "/metrics",
token: "",
});
logger.info("Express API toolkit installed");