hidePoweredBy() challenge is not passing

Tell us what’s happening:
I’m very positive that I have the middleware set correctly in myApp.js, but I cannot get it to pass when I submit the URL for the challenge. I do make sure that the code is running before submitting.

When I looked over the markdown file, it says assert.include(data.appStack, 'hidePoweredBy'); as part of its checks, and I feel like that may be the test that’s failing? I’m not sure how to fix this on my end. Please advise.

Your code so far

var express = require('express');
var app = express();

var helmet = require('helmet');
app.use(helmet.hidePoweredBy({ setTo: 'PHP 4.2.0' }))
module.exports = app;

var api = require('./server.js');
app.use(express.static('public'));

app.disable('strict-transport-security');
app.use('/_api', api);
app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});
var listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});
var express = require('express');
var app = express();

var helmet = require('helmet');
app.use(helmet.hidePoweredBy({ setTo: 'PHP 4.2.0' }))
module.exports = app;

var api = require('./server.js');
app.use(express.static('public'));

app.disable('strict-transport-security');
app.use('/_api', api);
app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});
var listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Hide Potentially Dangerous Information Using helmet.hidePoweredBy()

Link to the challenge:

Hello there,

Would you mind sharing a link to your project code?

Previously, we had an issue with this challenge, because of an update to helmet.js.

Project Code

Would you mind trying something which might not work:

Move this line:

app.use(helmet.hidePoweredBy({ setTo: 'PHP 4.2.0' }))

To be somewhere after:

app.disable('strict-transport-security');
app.use('/_api', api);

And move this line:

module.exports = app;

To the END of the file.

I tried it, and it didn’t work.
However, I did get a new error to show up on the console when I tried to submit the project URL:

Right. Yeah, I was afraid of that.

Last thing to try:

Leave the option empty for hidePoweredBy:

app.use(helmet.hidePoweredBy());

Have this at the bottom of the file:

module.exports = app;
var api = require('./server.js');
app.use(express.static('public'));
app.disable('strict-transport-security');
app.use('/_api', api);
app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});
var listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

Ensure there is no duplicate code, after doing that.

Hope that helps

Looks like…nope. Still not working.
I’ll post all my code again from myApp.js again, for reference:

var express = require('express');
var app = express();
var helmet = require('helmet');
app.use(helmet.hidePoweredBy())
module.exports = app;
var api = require('./server.js');
app.use(express.static('public'));
app.disable('strict-transport-security');
app.use('/_api', api);
app.get("/", function (request, response) {
  response.sendFile(__dirname + '/views/index.html');
});
var listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

Not even sure what else to try at this point.

I just passed with your project URL…

Do you have any sort of adblock? (with either access to freeCodeCamp or REPL.IT)

1 Like

Apparently just mashing the “submit” button got it to work eventually.

If it happens again. I’ll look into the adblock thing.

Thanks!

1 Like