Tell us what’s happening:
Hello everyone, I have the following error doing the install and require helmet challenge:
“throw new TypeError('Router.use() requires a middleware function but got a ’ + gettype(fn)).”
- I only cloned the github repo:
GitHub - freeCodeCamp/boilerplate-infosec: A boilerplate for the freeCodeCamp curriculum. - Installed and required helmet
- And it’s not working, I think the error is in this line
app.use(’/_api’, api);
Because you have to give a middleware function and the variable api contains an object.
I need help please
My code so far
MyApp.js
const express = require(‘express’);
const app = express();
const helmet = require (‘helmet’);
module.exports = app;
const 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’);
});
let port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(Your app is listening on port ${port}
);
});
package.json
{
“name”: “fcc-infosec-challenges”,
“version”: “0.0.1”,
“description”: “fcc backend boilerplate”,
“main”: “server.js”,
“scripts”: {
“start”: “node myApp.js”
},
“dependencies”: {
“express”: “^4.17.1”,
“helmet”: “3.21.3”
},
“keywords”: [
“node”,
“hyperdev”,
“express”,
“freecodecamp”
],
“license”: “MIT”
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0
Challenge: Install and Require Helmet
Link to the challenge: