title: Where should I extend prototype of ServerResponse in Sails.js?
body: <ul>
  <li>Sails.js v0.9.4</li>
  <li>Node.js v0.10.18</li>
  <li>Express.js v3.2.6</li>
  </ul>
  
  <p>I have written sails simple web application.
  I want to add new function to <code>ServerResponse</code> prototype for common error response like following.</p>
  
  <h3>UtilService.js</h3>
  
  <pre><code>require('http').ServerResponse.prototype.returnError = function (message) {
      console.error("Error: " + message);
      return this.view("./error", { errors: [{ stack: message }] });
  };
  </code></pre>
  
  <h3>FooController.js</h3>
  
  <pre><code>require("../services/UtilService");
  </code></pre>
  
  <p>Above codes work well. But I don't write same snippet to all controllers.
  How can I keep DRY? In other words, which file should I write above extention code?</p>
  
  <hr>
  
  <h1>Added at 2013-09-25 09:26 UTC</h1>
  
  <p>Thank you for advices and suggestions.
  I added special logic to <code>config/bootstrap.js</code> because I want to run the code for prototype modifying only once.
  This looks working fine.</p>
  
  <h3>config/bootstrap.js</h3>
  
  <pre><code>module.exports.bootstrap = function (cb) {
    cb();
    require('http').ServerResponse.prototype.returnError = function (message) {
      console.error("Error: " + message);
      return this.view("./error", { errors: [{ stack: message }] });
    };
  };
  </code></pre>