Error: Backend & APIs / Basic Node and Express lesson 4

For lesson 4 of Basic Node and Express, I’m getting a TypeError: Object prototype may only be an Object or null at /userPath/free-code-camp/boilerplate-express/public

The line of code I used is this : app.use(express.static("/public", __dirname +"/public"));

The mount path is the first argument to app.use() not express.static().

Move the first "/public" out of express.static and put it before it so that it is app.use that takes two arguments.

Hint if needed:

app.use("/someMountPath", express.static(__dirname + "/someFolder"));

Thanks! That totally makes sense.

Now I’m stuck on the “Use the .env file” one, lesson 6, even though my API response is correct on my localhost:3000/json. I tried various ways of re-saving the response variable, or just doing it within the object itself. Also, how do you post in code block format here?

app.get(’/json’, function(req, res) {
var response = “Hello json”;
if (process.env.MESSAGE_STYLE === “uppercase”) {
//response = response.toUpperCase();
res.json({“message:”: response.toUpperCase()})
}
else {
res.json({“message”: response});
}
});

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.