Hint: Always enable express.json() before accessing req.body [OK]
Common Mistakes:
Thinking res.send must be res.json
Using app.get for creation routes
Assuming saveUser must be async here
5. You want to create an Express route that accepts JSON data to create a new product and respond with the created product including an ID. Which code snippet correctly implements this?
Step 1: Use correct HTTP method and access JSON body
The route uses app.post and accesses req.body which is correct for creating a product.
Step 2: Add an ID and respond with status 201 and JSON
Assigning product.id = Date.now() simulates creating an ID. Responding with res.status(201).json(product) sends the created product with proper status.