app.set ('x-powered-by', false) does not work on expressjs

1

Hello, in my main code of my app, with the use of express, I'm trying to remove the "x-powered-by" header, and I've used both

app.disable("x-powered-by")

how much

app.set("x-powered-by", false)

In addition, I've already tried using the helmet module.

But, no way comes up and the header continues to appear in the requests.

Here is the structure of my code:

const express        = require('express'),
      app            = express(),
      http           = require('http'),
      cors           = require('cors'),
      helmet         = require('helmet'),

app.set('x-powered-by', false);

...

app.use(cors());
app.use(helmet());

...

http
.createServer(app)
.listen(port, () => {
    console.log('running in port ${port}');
});
    
asked by anonymous 07.07.2017 / 22:29

1 answer

1

I use this way, with the helmet:

app.use(
    helmet({
        hidePoweredBy: {
            setTo: 'Renewable energies, love and good music'
        }
    })
);

And if you want you can pass an empty string in setTo .

    
07.07.2017 / 23:13