Search
 
SCRIPT & CODE EXAMPLE
 

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)

})

Comment

PREVIOUS NEXT
Code Example
Javascript :: vscode search shortcut 
Javascript :: assign-only-if-property-exists-in-target-object 
Javascript :: boilerplate functional component for DataGrid 
Javascript :: insert image in jsp page 
Javascript :: ansel array sort 
Javascript :: get range of items in list javascript react native 
Javascript :: Creating Variables In Self Evoking Function 
Javascript :: Appium find Android Element with Xpath using Javascript 
Javascript :: select random quotes from array called anecdotes 
Javascript :: javascript assignment by reference or value 
Javascript :: phaser max size of group or pool 
Javascript :: Setting Multiples Properties With Array 
Javascript :: testing code through local server using express.js 
Javascript :: Make Floating label TextInput with password show/hide in react native 
Javascript :: javascript quotes 
Javascript :: react show more component 
Javascript :: how to display unicode in javascript 
Javascript :: dayofyear mongodb 
Javascript :: If you wish to set a method equal to another method in the class 
Javascript :: prisma bytes 
Javascript :: livewire multiple root elements detected. this is not supported 
Javascript :: How to Loop Through an Array with a do…while Loop in JavaScript 
Javascript :: swal on submit angular with cancel butotn 
Javascript :: How to redirect to login page if not logged in javascript 
Javascript :: Solution-4--solution options for reverse bits algorithm js 
Javascript :: hide and show button react js 
Javascript :: redirect in react-router-dom v6 
Javascript :: && condition in javascript 
Javascript :: js array map concat 
Javascript :: how to check if input field has value 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =