Basic Node and Express - Get Route Parameter Input from the Client

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: boilerplate-express - Replit

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:

hello and welcome to fcc forum :slight_smile:

  • you are attempting to extract “word” from “req.params.word”, which is wrong!!

consider this code from example

req.params: {userId: ‘546’, bookId: ‘6754’}

  • where userId and bookId is “destructured” from? you are supposed to do that with “word” as well

happy learning :slight_smile:

thank you! i solved it

1 Like

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