Exercise 7 : EXPRESS ROUTES CODE CHALLENGES

Hello,

I’m confused by req.query.name. In the lesson, we only added a .something ie .id or .name when the route had a :id or :name in it. How can we request req.query.name from '/soups'?

const express = require('express');
const app = express();

const PORT = process.env.PORT || 4001;

const soups = ['gazpacho', 'borscht', 'primordial', 'avgolemono', 'laksa'];

app.listen(PORT, () => {
  console.log(`Server is listening on port ${PORT}`);
});

app.post('/soups', (req, res, next) => {
  const newSoupName = req.query.name;
  soups.push(newSoupName);
  res.status(201).send(newSoupName);
});

https://www.codecademy.com/paths/back-end-engineer-career-path/tracks/becp-build-a-back-end-with-node-express-js/modules/fscp-learn-express-routes/lessons/learn-express-routes-code-challenge/exercises/code-challenge-post

Hey there,
Note that it’s req.query, not req.params. Req.query would take info from a url like soups.com/soups?soup=soup.

1 Like

Ahhhhh, yes - thank you.

1 Like