title: How to add custom function to response object in Node.JS
body: <p>In my API-application I have a fixed response for errors in different parts. As you can see <code>res.status(400).json({"error": "Invalid input"})</code> is repeating a lot, in different files and modules actually. </p>
  
  <p>I could create module-function <code>invalidInput(res)</code>, which will eliminate duplication, but I really want this to be global part of <code>res</code> object, like <code>res.invalidInput()</code>. </p>
  
  <p>How could I make it in JS/Node.JS?</p>
  
  <pre><code>router.get("/users", function(req, res) {
      // ...
      if (error) {
          return res.status(400).json({"error": "Invalid input"});
      }
  });
  
  router.get("/items", function(req, res) {
      // ...
      if (error) {
          return res.status(400).json({"error": "Invalid input"});
      }
  });
  
  // etc
  </code></pre>