Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs api find data with id

//nodejs api find data with id (pass id througn url)
app.get('/:productID',(req, res) =>{

 //   console.log(req);
 //   console.log(req.params);
    const {productID} = req.params;
    const singleProduct = products.find((product) => product.id ===Number(productID));
    if(!singleProduct){
        return res.status(404).send('Product not found')
    }
    res.json(singleProduct)

})

 
PREVIOUS NEXT
Tagged: #nodejs #api #find #data #id
ADD COMMENT
Topic
Name
6+6 =