Can’t get rid of header X-Powered-By:Express

Can’t get rid of header X-Powered-By:Express

I am running a server on nodejs with express. I can’t seem to get rid of the header:

I was wondering if there is any way to get rid of this header or do I have to live with it?


Solution 1:

In Express >= 3.0.0rc5:


Here is a simple middleware that removes the header in earlier versions of Express:

app.use(function (req, res, next) {

Solution 2:

Just to piggy-back on rjack’s answer, you could also (optionally) just change (set) the X-powered-by header to something much cooler/custom like this:

app.use(function (req, res, next) {
  res.header("X-powered-by", "Blood, sweat, and tears")

Solution 3:

As of Express v3.0.0rc5, support for disabling the X-Powered-By header is built in:

var express = require('express');

var app = express();

Solution 4:

From the source ( In Express 4.X just set the app using the line below;

app.set('x-powered-by', false) // hide x-powered-by header!

Solution 5:

Here’s a handy middleware you can drop in to swap out X-Powered-By:

function customHeaders( req, res, next ){
  // Switch off the default 'X-Powered-By: Express' header
  app.disable( 'x-powered-by' );

  // OR set your own header here
  res.setHeader( 'X-Powered-By', 'Awesome App v0.0.1' );

  // .. other headers here


app.use( customHeaders );

// ... now your code goes here

Setting X-Powered by in this case would override the default ‘Express’, so you do not need to both disable AND set a new value.

Related:  How and why does 'a'['toUpperCase']() in JavaScript work?

Solution 6:

Maybe this could be obvious to the more seasoned Express users, but only this worked for me:

app.configure(function() {
    app.use(function (req, res, next) {