Node.js: Module Does Not Recognize Schema
On server.coffee I have: User = mongoose.model 'User', s.UserSchema addEntryToCustomer = require './lib/addEntryToCustomer' and on addEntryToCustomer.coffee I have: module.export
Solution 1:
In node.js, modules run in their own context. That means the User
variable doesn't exist in addEntryToCustomer.coffee.
You can either make User
global (careful with it):
global.User = mongoose.model 'User'
Pass the user variable to the module:
module.exports = (User, phone, res, req) ->
User.find {account_id: phone.account_id }, (err, user) -> …
Or reload the model:
mongoose = require'mongoose'module.exports = (phone,res,req) ->
User = mongoose.model 'User'
User.find {account_id: phone.account_id }, (err, user) ->
It's also possible to add methods to the Models themselves, though you need to do that when defining the Schema: http://mongoosejs.com/docs/methods-statics.html
Post a Comment for "Node.js: Module Does Not Recognize Schema"