node.js export module function


I have a problem with node.js. I am creating a blog and I have two archives: sessions.js users.js

in sessions.js :

function SessionsDAO(db) {
this.startSession = function(username, callback) {....}
module.exports.SessionsDAO = SessionsDAO;

in users.js

var Session = require('./sessions');
var s = new Session();

but shows me error:

object is not a function
TypeError: object is not a function
Problem courtesy of: Bicu


require returns the exports object, so:

var SessionsDAO = require('./sessions').SessionsDAO;
var s = new SessionsDAO();
Solution courtesy of: josh3736


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.