Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

send data from a file to frontend nodejs

//send all data from a file to frontend

app.get('/', (req, res) =>{
    //   res.json([{name: 'asfand'},{name: 'saad'}])
    const newproducts = products.map((product) =>{
        const {id, name, image} = product;
        return{id, name , image}
    })    
    res.json(newproducts)
 //   res.json(products)
})

//send only one (find by id)

app.get('/', (req, res) =>{
    const singleproduct = products.find((product) => product.id ===1)
    res.json(singleproduct)
})
 
PREVIOUS NEXT
Tagged: #send #data #file #frontend #nodejs
ADD COMMENT
Topic
Name
7+2 =