expressjsHow can I disable the X-Powered-By header in Express.js?
To disable the X-Powered-By header in Express.js, you can use the app.disable('x-powered-by')
function. This will prevent Express from including the X-Powered-By header in the response.
Example code
const express = require('express');
const app = express();
app.disable('x-powered-by');
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000);
Output example
Server listening on port 3000
The app.disable('x-powered-by')
function takes a single string argument, which is the name of the header you want to disable. In this case, it is x-powered-by
.
You can also disable multiple headers at once by passing an array of strings. For example:
app.disable(['x-powered-by', 'x-frame-options']);
This will disable both the X-Powered-By and X-Frame-Options headers.
Helpful links
More of Expressjs
- How do I set the time zone in Express.js?
- How can I use Express.js to generate a zip response?
- How do I use Yarn to add Express.js to my project?
- How do I find Express.js tutorials on YouTube?
- How can I use Node.js and Express together to create a web application?
- How can I use Express.js to yield results?
- How can I use an ExpressJS webhook to receive data from an external source?
- How can I use Express.js and Winston together to create a logging system?
- How do I use Express.js to handle x-www-form-urlencoded data?
- How can I use Express.js with TypeScript?
See more codes...