I am miss understanding this concept in nodejs. I want to place a function in a folder at ./models/user lets say to represent a model I use for user. Then I want to use these as functions somewhere else. The issue I always run into is when do something like user.something it doesn't handle like a function. I am misunderstanding how this works.
The model would look something like this:
//model/user.js
function User() {
this.foo = null;
}
User.prototype.hashPass = function (password, callback) {
//Code that hashes a password
callback(err, hash);
};
User.prototype.insertUser = function (email, password, callback) {
//Code that inserts a user and returns some 'done' callback
callback(err, done);
};
module.exports = User;
And somewhere else in my program lets say passport.js I want to do this:
//config/passport.js
var User = require('../models/user);
var user = new User();
async.waterfall([
//how does this look
//EDIT ATTEMPTED HERE
user.hashPass(password, function(err, result) {
}),
user.insertUser(result, function(err, rows) {
})
], //some callback );
Made some edits to help to clarify what I am trying to accomplish here.
EDIT: This link shows how to do async waterfalls with multiple callbacks
Code based on EDIT / Understanding:
async.series([
function(callback) {
user.hashPass(password, function(err, result) {
callback(err,result);
})
}
], function(err, result) {
if (err) return err;
console.log('test',result);
});