Slava Fomin II Slava Fomin II - 1 year ago 156
Javascript Question

How to disable or replace X-Powered-By header in Sails.js application

When I run Sails.js application, it adds the following HTTP header automatically to every response:

X-Powered-By: "Sails <>"

Is it possible to disable or override it?

Answer Source

Yes, it's quite possible.

You will need to disable the Sails's middleware called poweredBy and also tell Express.js server not to add it's own header.

Just update your config/http.js configuration file to looks like this:

module.exports.http = {
  middleware: {

    disablePoweredBy: function(request, response, next) {
      var expressApp =;
//    response.set('X-Powered-By', 'One Thousand Hamsters');

    order: [
//    ...
//    'poweredBy',
//    ...

Here, we are retrieving an instance of Express Application from Sails hooks and then using it's disable() method to set the x-powered-by configuration parameter to false value. That will prevent the header from appearing.

And in order to enable this custom middleware, you will need to add it to the order array. You can just replace poweredBy middleware with disablePoweredBy.

Also, by un-commenting the response.set() method you can set your own header value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download