how to remove X-Powered-By in ExpressJS

MajidTaheri picture MajidTaheri · May 23, 2012 · Viewed 53.4k times · Source

I want to remove X-Powered-By for Security,Save Bandwidth in ExpressJS(node.js). how to do it? it could be filter(app.use) ?

app.use(function(req,res,next_cb){ /* remove X-Powered-By header */ next_cb(); }

Answer

ahcox picture ahcox · Oct 24, 2012

Don't remove it; ask Express not to generate it in the first place:

https://stackoverflow.com/a/12484642/506073

Go to your app.js and just after:

var app = express();

Add:

app.disable('x-powered-by');