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
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
Reset to default 19You need to do res.end
instead of res.send
. res.send
is a part of express
module and not of core http module
.