Hi,
I’ve been having the same problem. I cannot pass this part no matter what i try. I dont really think it is about the code, though, nor the localhost. This is the code i’ve been using:
require('dotenv').config();
let express = require('express');
let app = express();
let bodyParser = require('body-parser');
//body parser
app.use(bodyParser.urlencoded({ extended: true }));
//logger middleware
app.use(function(req, res, next) {
console.log(req.method + " " + req.path + " - " + req.ip);
next();
});
// serve css
app.use("/public", express.static(__dirname + "/public"));
// serve html
app.get("/", function(req, res) {
res.sendFile(__dirname + "/views/index.html");
});
// use env
app.get("/json", function(req, res) {
let message = "Hello json";
if (process.env.MESSAGE_STYLE === "uppercase") {
message = message.toUpperCase();
}
res.json({ "message": message });
});
// time server
app.get("/now", function(req, res, next) {
req.time = new Date().toString();
next();
}, function(req, res) {
res.json({ time: req.time });
});
//echo server
app.get("/:word/echo", function(req, res) {
res.json({ echo: req.params.word });
});
//get name
app.get("/name", function(req, res) {
var firstName = req.query.first;
var lastName = req.query.last;
res.json({ name: firstName + " " + lastName });
});
//post name
app.post("/name", function(req, res) {
// Handle the data in the request
var string = req.body.first + " " + req.body.last;
res.json({ name: string });
});
// server.js
module.exports = app;
and this is the response i’m having from my localhost
However, the result seems to be this:
*// running tests
- Test 1 : Your API endpoint should respond with the correct name
- Test 2 : Your API endpoint should respond with the correct name
// tests completed*
what i found out in the browser console is the every time i hit submit only in that part of the course, this error pops up(twice, as many times as the tests run)
which is NOT the response of a falty submission by the user. Below i post a picture of one wrong answer on purpose in the GET query part
———–
So that made me think it might be a browser issue, or my OS issue worst case scenario.
However, I:
- tunneled with ngrok, same result
- tried with replit, same result
- tried another browser, same result
- tried incognito, clear cache hard reload, same result
- i tried the ngrok like through mobile (ios), same result.
I dont really know if there’s anything else I could try.