title: Simple Q Promises Node Example
body: <p>I'm trying to wrap my head around the Q library/promises in general so I can implement it in my node application, but I'm having trouble finding something concise and specific enough to quickly get started. </p>
  
  <p>Could someone help me translate this code into an asycronous pattern using Q's promise library?</p>
  
  <pre><code>// # For those new to coffeescript
  
  // # '(params) -&gt;' === 'function (params) {}' in coffeescript
  // # '@' === 'this' in coffeescript
  
  
  // # NPM
  Q = require 'q'
  
  // # Database class
  module.exports = class Database
  
    constructor: () -&gt; 
      // # mongoose
      @mongoose = require('mongoose')  
  
      // # Make database connection
      @connect_database()
  
    connect_database: () -&gt;
      try
        @mongoose.connect('mongodb://127.0.0.1:27017/database')
        return 'Database connected'.green
      catch e
        return ('Database connection error: ' + e.toString()).red
  </code></pre>
  
  <p>Once I see something directly applicable I think it will be much easier for me to convert the rest of my application to this pattern.</p>