How to fix the Express req.body undefined error

 Now, if we send a JSON data to the /users route, we will see an undefined in the console. To fix this error, first we need to parse our incoming requests by using the express.json() , express.urlencoded() middleware functions. const express = require(“express”); const app = express(); // middleware app.use(express.json()); app.use(express.urlencoded()); app.post(“/users”, (req, res) => { console.log(req.body); }); app.listen(3000, () => console.log(`App is …

How to fix the Express req.body undefined error Read More »

set counter i n react

  <button className=“btn btn-success” onClick={() => setCount(1)}>Reset</button> const [count, setCount] = useState(1); <button className=“btn btn-primary” onClick={() => setCount(prevCount => prevCount – 1)}>–</button> <input className=“” type=“text” value={count}></input> <button className=“btn btn-primary” onClick={() => setCount(prevCount => prevCount + 1)}>+</button>

update object value in an array in javascript

  const storage= [ { id:1, name:“kahnu”, email:“[email protected]”, age:21, phone:1234567890 }, { id:2, name:“kahnu2”, email:“[email protected]”, age:22, phone:1234567890 }, { id:3, name:“kahnu3”, email:“[email protected]”, age:23, phone:1234567890 } ] const objIndex = storageData.findIndex((obj => obj.id == ‘1’)); storageData[objIndex].name = ‘new name’; storageData[objIndex].email = ‘new email’; storageData[objIndex].age = ‘new age’; console.log(“After update: “, storageData[objIndex])