Writing to the database
Now that we're receiving the request body as JSON, we can put this data in our database.
Let's require our Item model at the top of the controller. Then, in the create method, we'll create a new Item, using the request body.
Let's now add a try/catch block, too. In the try, we'll
await model.save();. Since we're using async/await, we'll need to make this controller method an
async method, too.
Click to load comments...