Reputation: 13
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
Upvotes: 1
Views: 2527
Reputation: 63587
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.
Upvotes: 3