33

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?

0

1 Answer 1

60

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.