Tell us what’s happening:
I think my code is right? But it keeps error.
Output
// running tests
Test 1 : Your echo server should repeat words correctly
Test 2 : Your echo server should repeat words correctly
// tests completed
let express = require('express')
let app = express()
// console.log('Hello World')
// app.use((req, res, next) => {
// let string = req.method + " " + req.path + " - " + req.ip
// console.log(string)
// next()
// })
// app.get('/', (req, res) => {
// res.sendFile(__dirname + "/views/index.html")
// })
// app.use('/public', express.static(__dirname + "/public"))
// app.get('/json', (req, res) => {
// if (process.env.MESSAGE_STYLE === "uppercase") {
// response = "Hello json".toUpperCase()
// res.json({ message: response })
// } else {
// response = "Hello json"
// res.json({ message: response })
// }
// })
// const middleware = (req, res, next) => {
// req.time = new Date().toString();
// next();
// };
// app.get('/now', middleware, (req, res) => {
// res.json({
// time: req.time
// });
// });
app.get('/:word/echo', (req, res) => {
const { word } = req.params.word
res.json({ 'echo': word })
})
module.exports = app;
Your project link(s)
solution: https://replit.com/@eind/boilerplate-express
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15
Challenge: Basic Node and Express - Get Route Parameter Input from the Client
Link to the challenge: