1

Hi I am writing the following code

var http=require('http')

var makerequest=function(message)
{
   var options= {host:'localhost', port:8080, path:'/',method:'POST'}
   var request=http.request(options,function(response)
  {
    response.on('data',function(data)
      {
          console.log(data);
      });
   });
   request.write(message);
   request.end();
}

exports=makerequest;

app.js :

var makerequest=require('./make_request.js');

makerequest("Here's looking at you, kid");

I am getting this error

TypeError: Object is not a function

Can someone help on this.I tried searching but couldnt find a solution. Thanks

3
  • 2
    which line throws that error? Commented Mar 11, 2015 at 13:25
  • module.exports not exports. Commented Mar 11, 2015 at 13:27
  • was about to answer but Andy got it, Commented Mar 11, 2015 at 13:28

1 Answer 1

3

require returns an object which references the value of module.exports for a given file. You should use module.exports instead of exports in your code instead.

You can find more information here on the differences between the two.

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

2 Comments

The previous error is gone.There is new error that says: events.js:85 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:983:19)
@user2201629, that's a completely different question, I'm afraid. Mark this as answered and then add a new question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.