title: Including JavaScript class definition from another file in Node.js
body: <p>I'm writing a simple server for Node.js and I'm using my own class called <code>User</code> which looks like:</p>
  
  <pre><code>function User(socket) {
      this.socket = socket;
      this.nickname = null;
  
      /* ... just the typical source code like functions, variables and bugs ... */
  
      this.write = function(object) {
          this.socket.write(JSON.stringify(object));
      }
  };
  </code></pre>
  
  <p>and then later in the process I'm instantiating it a lot:</p>
  
  <pre><code>var server = net.createServer(function (socket) {
      /* other bugs */
      var user = new User(socket);
      /* more bugs and bad practise */
  });
  </code></pre>
  
  <p>Can I move my <code>User</code> class definition to another javascript file and "include" it somehow?</p>