Hi, I'm curious convention on how to design modules which has dependencies. For example if I've got an auth module with a function called authenticate which in turn uses a UserRepository object (which in turn uses a database library object like node-mysql) which communicates with the database, how should I design the auth module? I'm really interested in ways which makes the code easier to unit test.
Is this a good way? (Pseudo code): Index.js: var db = new MysqlClient(...) var users = new UserRepository(db) var auth = require('./lib/auth')(users) auth.authenticate(...) Auth.js: module.exports = function(users) { return { authenticat: function(email, password, callback) { user = users.get({ email: email}, function(user) { if (user) callback(null, user) else callback(new Error('Authentication failed')) } }, register: function(...) {}, etc... } } Is there a better, cleaner way of doing it? -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en