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

I think I’ve done everything correctly.

const http = require('http');
const hostname = '';
const port = 3000;
const express = require("express")
const app = express();

app.get("/:word/echo", (req, res) => {
  const word = req.params.word;
    echo: word
app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);

I have know idea what’s wrong!

Are you using the correct boilerplate code? It has the dependencies you need.

Is that all the code in the file? Where is the export?

module.exports = app;

The route code itself looks fine and should be passing.

What is the error it is showing to you ?

I got the following error:
// running tests
Test 1 : Your echo server should repeat words correctly
Test 2 : Your echo server should repeat words correctly
// tests completed
// console output

Try using

const  {word} = req.params

This doesn’t make sense, because req.params is the object {"word":"hithere"} when the client sends a GET request to the “/hithere/echo” route.

The route code isn’t the issue and passes the test for me.

This is why I asked you if you have followed the necessary steps to have a proper working local version of the challenge.

Please post a repo with all your code so we can see it all.

I know, that’s why i am suggesting you to try using destructuring the req.params object

Please use the boilerplate provided to you for the challenges.

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