Baseline security headers
Reducing exposure to common browser and web attacks in an Express application.
Express.js · Module
Helmet is Express middleware that sets security-related HTTP response headers. Install it separately and register helmet() with app.use().
Helmet is an additional middleware module for Express that improves application security by adding security-related HTTP response headers. Register it with app.use so those headers are applied to responses handled by the application.
app.use(helmet());Middleware function
const express = require('express');
const helmet = require('helmet');
const app = express();
app.use(helmet());
app.get('/', (_req, res) => res.send('ok'));
app.listen(3000);Install Helmet separately, then register its middleware on the Express application.
Reducing exposure to common browser and web attacks in an Express application.
Enforcing HTTPS preference for browsers through the Strict-Transport-Security response header.
Controlling which page behaviors are allowed with Content-Security-Policy.
Helmet is middleware that sets security-related HTTP response headers. It is installed as a separate module and registered with app.use(helmet()).
Follow-up: Which Express setting complements Helmet by removing the framework-identifying header? Use app.disable('x-powered-by').
Helmet sets several headers by default, including Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, and X-Frame-Options. These headers help control browser behavior and reduce exposure to common web attacks.
Follow-up: Can the defaults be changed? Yes; each header can be configured or disabled.
Helmet is not part of Express's built-in middleware list; it is an additional middleware module. The documented installation command is npm install helmet, after which the module is imported or required.
Follow-up: How would you use it with CommonJS? Require it with const helmet = require('helmet') and pass helmet() to app.use.
app.use()app.disable()express()X-Powered-By