3
var url = require('url');
var http = require('http');

http.createServer(function (req, res) {
  var url_parts = url.parse(req.url, true);
  var q = url_parts.query;
  console.log(q.query);

   res.setHeader('Content-Type', 'application/json');
   res.send(JSON.stringify({ a: 1 }));

console.log(q.query);
}).listen(8080);

Using this code I'm able to receive request, but I'm unable to respond to it. It shows TypeError: res.send is not a function

1 Answer 1

19

You need to do res.end instead of res.send. res.send is a part of express module and not of core http module.

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

1 Comment

Thanks, I wasted 5 hours on this :(

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.