Node.JS export function without object wrapper

Bryan Field picture Bryan Field · May 3, 2011 · Viewed 14.1k times · Source

I am looking at Node.JS request and notice that you can use

var request = require('request');
request(...)

But when I try to do something similar like in the module I try

exports = function() {}

it does not work. The only way I know to use is

var request = require('request').request;
request(...)

and

exports.request = function() {}

How can I set the whole export to a function instead of adding a function to the export object?

A hint might be available in the request source code but I am finding it hard to figure out what is going on. Can you help?

Answer

Raynos picture Raynos · May 3, 2011

You need to overwrite it as

module.exports = function() {}

Merely writing exports = function() {} creates a new local variables called exports and hides the exports variable living in module.exports