title: Error in function to update an user [node.js]
body: <p>I have an error when i try to update the bio on a user with postman. I use mongoDB for the database. Looks like it's a problem when i try to send the docs in the response but i don't see how to fix it</p>
  <p>Here is the code of userController that doesn't work :</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>module.exports.updateUser = async (req, res) =&gt; {
      if (!ObjectId.isValid(req.params.id))
        return res.status(404).send("ID unknown : " + req.params.id);
    
      try {
        await UserModel.findOneAndUpdate(
          { _id: req.params.id },
          {
            $set: {
              bio: req.body.bio,
            },
          },
          { new: true, upsert: true, setDefaultsOnInsert: true },
          (err, docs) =&gt; {
              console.log(docs);
              if (!err) return res.send(docs);
              else return res.status(500).json({ message: err });
          }
        );
      } catch (err) {
        return res.status(500).json({ message: err });
      }
  };</code></pre>
  </div>
  </div>
  </p>
  <p>And the error is as follows:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>node:events:371
        throw er; // Unhandled 'error' event
        ^
  
  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at new NodeError (node:internal/errors:371:5)
      at ServerResponse.setHeader (node:_http_outgoing:573:11)
      at ServerResponse.header (/home/pt/Documents/back_sport_app/api/node_modules/express/lib/response.js:771:10)
      at ServerResponse.send (/home/pt/Documents/back_sport_app/api/node_modules/express/lib/response.js:170:12)
      at ServerResponse.json (/home/pt/Documents/back_sport_app/api/node_modules/express/lib/response.js:267:15)
      at ServerResponse.send (/home/pt/Documents/back_sport_app/api/node_modules/express/lib/response.js:158:21)
      at /home/pt/Documents/back_sport_app/api/controllers/userController.js:36:34
      at /home/pt/Documents/back_sport_app/api/node_modules/mongoose/lib/model.js:4923:18
      at processTicksAndRejections (node:internal/process/task_queues:78:11)
  Emitted 'error' event on Function instance at:
      at /home/pt/Documents/back_sport_app/api/node_modules/mongoose/lib/model.js:4925:15
      at processTicksAndRejections (node:internal/process/task_queues:78:11) {
    code: 'ERR_HTTP_HEADERS_SENT'
  }
  [nodemon] app crashed - waiting for file changes before starting...</code></pre>
  </div>
  </div>
  </p>