mongoose = require 'mongoose'
class Locations
constructor: @(host, port) ->
@db = new mongoose 'locations', new Server(host, port, {auto_reconnect: true}, {})
this.db.open ->
null
getAll: (callback) ->
@db.collection 'locations', (err, locations_collection) ->
if err?
callback err
else
callback null, locations_collection
null
exports.Locations = Locations
I have that in a file called locations.coffee and in my app.js, I have
locationsModel = require '../models/locations'
locationModel = new locationsModel 'localhost', 27017
But apparently it never gets instantiated because I get
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: host is not defined
I’ve not seen that method of defining models using Mongoose before.
Have you tried using their model definition guide? Converting it to Coffeescript should be relatively easy.