title: Error [ERR_HTTP_HEADERS_SENT] Cannot set headers after they are sent to the client
body: <pre><code>    at ServerResponse.setHeader (_http_outgoing.js:470:11)
      at ServerResponse.header (C:\root\node_modules\express\lib\response.js:771:10)
      at ServerResponse.send (C:\root\node_modules\express\lib\response.js:170:12)
      at ServerResponse.json (C:\root\node_modules\express\lib\response.js:267:15)
      at ServerResponse.send (C:\root\node_modules\express\lib\response.js:158:21)
      at grade.save (C:\root\route\api\listsData.js:223:32)
      at C:\root\node_modules\mongoose\lib\model.js:4604:16
      at C:\root\node_modules\mongoose\lib\utils.js:268:11
      at $__save.error (C:\root\node_modules\mongoose\lib\model.js:472:16)
      at C:\root\node_modules\kareem\index.js:246:48
      at next (C:\root\node_modules\kareem\index.js:167:27)
      at next (C:\root\node_modules\kareem\index.js:169:9)
      at Kareem.execPost (C:\root\node_modules\kareem\index.js:217:3)
      at _handleWrapError (C:\root\node_modules\kareem\index.js:245:21)
      at C:\root\node_modules\kareem\index.js:272:14
      at _next (C:\root\node_modules\kareem\index.js:94:14)
  Emitted 'error' event at:
  </code></pre>
  
  <p>Please help, I was facing with this issue almost 3 days now, below is my backend nodejs code:
  GradeModel</p>
  
  <pre><code>const mongoose = require('mongoose');
  
  const GradeSchema = new mongoose.Schema({
    name: {
      type: String,
      maxlength: 100,
      required: true,
      unique: true
    }
  })
  
  module.exports = Grade = mongoose.model('Grade', GradeSchema);
  </code></pre>
  
  <p>AddGradeRoute</p>
  
  <pre><code>  '/add/grade',
    [
      check('name', 'grade name is require')
        .not()
        .isEmpty()
    ],
    auth,
    admin,
    (req, res) =&gt; {
      const errors = validationResult(req);
      if (!errors.isEmpty()) res.status(400).send({ errors: errors.array() });
  
      const grade = new Grade(req.body);
  
      grade.save((err, doc) =&gt; {
        if (err) res.status(400).send({ success: false, err });
        return res.status(200).send({
          success: true,
          grade: doc,
          msg: 'Grade add successfully'
        });
      });
    }
  );
  </code></pre>
  
  <p>The issue is when I tried to add grade with the post request it's working fine, but if I put blank field and send the request again, app is crashed and it returns with the error above 'Cannot set headers after they are sent to the client'. Thank you.</p>