How can I pass a variable while using `require` in node.js?

I think what you want to do is:

var user = require('./user')(client)

This enables you to have client as a parameter in each function in your module or as module scope variable like this:

module.exports = function(client){

 ...

}

This question is similar to: Inheriting through Module.exports in node

Specifically answering your question:

module.client = require('./database.js').client;
var user = require('./user.js');

In user.js:

exports.find = function(id){
  // you can do:
  // module.parent.client.query.....
}

Tags:

Node.Js