Postman cannot display individual details of nodes when using parameters
P粉739079318
P粉739079318 2024-04-02 19:59:35
0
1
366

In my react project I need to get a single detail to the details page using parameters but the response is not being sent to postman. After sending the request, the response is not coming to Postman

index.js
import express from "express";
import cors from "cors";
import mongoose from "mongoose";
import { userRouter } from "./routes/users.js"
import { recipesRouter } from "./routes/recipes.js"
const app = express();
app.use(express.json());

app.use(cors());

 app.use("/auth", userRouter);
 app.use("/recipes", recipesRouter);

mongoose.connect(
"xxxxxxxxxxxxxxxxxxxxxx"
);
app.listen(3001, () => console.log("SERVER STARTED"));

router

import express from "express";
import mongoose from "mongoose";
import { RecipeModel } from "../models/Recipes.js"
import { UserModel } from "../models/User.js";
const router = express.Router();
router.get("/createrecipe/:id",  async (req, res) =>{
let result =await RecipeModel.findOne({id:req.params.id});
if(result){
    res.send(result)
}else{
    res.send('no recipe')
}})

Postman get--http://localhost:3001/createrecipe/1

<body>
    <pre>Cannot GET /createrecipe/1</pre>
</body>

You need to view the details of the single item in the details page and postman.

P粉739079318
P粉739079318

reply all(1)
P粉680487967

In app.use("/recipes",recipesRouter), you are adding the /recipes prefix to all routes in recipesRouter, but you Calling http://localhost:3001/createrecipe/1 instead of http://localhost:3001/recipes/createrecipe/1

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template