app.post("/properties", async (req, res, next) => { try { const { body } = req; const property = new PropertyModel(body); await property.save(); return res.status(201).send(formatProperty(property)); } catch (error) { if (error.name === "ValidationError") { error.status = 400; } next(error); } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter