node.js export module function

Problem

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();
s.startSession(username);

but shows me error:

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

Solution

require returns the exports object, so:

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

Discussion

There is currently no discussion for this recipe.

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