You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexpress=require('express');constrouter=express.Router();constNote=require('../models/Note');const{ body, validationResult }=require('express-validator');constfetchuser=require('../middleware/fetchuser');// ROUTE 2: Add a new Note using: POST "/api/notes/addnote". Login requiredrouter.post('/',fetchuser,[body('title','Enter a valid title').isLength({min: 3}),body('description','Description must be atleast 5 characters').isLength({min: 5}),],async(req,res)=>{try{const{ title, description, tag }=req.body;// If there are errors, return Bad request and the errorsconsterrors=validationResult(req);if(!errors.isEmpty()){returnres.status(400).json({errors: errors.array()});}constnote=newNote({
title, description, tag,user: req.user.id})constsavedNote=awaitnote.save()res.json(savedNote)}catch(error){console.error(error.message);res.status(500).send("Internal Server Error");}})module.exports=router
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: