Tell us what’s happening:
Server returns the correct json object after submitting the form but both tests fail with the message: “Your API endpoint should respond with the correct name” and i dont know what to do.
###Your project link(s)
solution:
let express = require('express');
const { log } = require('fcc-express-bground');
require('dotenv').config();
let bodyParser = require('body-parser');
let app = express();
console.log("Hello World");
app.use((req, res, next) => {
console.log(req.method + ' ' + req.path + ' - ' + req.ip);
next();
});
app.use("/public", express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({ extended: false }));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
});
app.get("/:word/echo", (req, res) => {
res.json({ "echo": req.params.word });
});
app.get("/name", (req, res) => {
res.json({ "name": req.query.first + " " + req.query.last });
});
app.post("/name", (req, res) => {
res.json({ "name": req.body.first + " " + req.body.last });
});
app.get("/now", (req, res, next) => {
req.time = new Date().toString();
next();
}, (req, res) => {
res.json({ "time": req.time });
});
app.get("/json", (req, res) => {
if (process.env.MESSAGE_STYLE == "uppercase") {
res.json({ "message": "HELLO JSON" });
} else {
res.json({ "message": "Hello json" });
}
});
module.exports = app;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0
Challenge Information:
Basic Node and Express - Get Data from POST Requests
