JavaScript Node js`res.send不是函数错误`

Bug*_*ggy 1 javascript http node.js

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);
Run Code Online (Sandbox Code Playgroud)

使用此代码我能够收到请求,但我无法回复它.表明TypeError: res.send is not a function

vib*_*97a 13

你需要做res.end而不是res.send.res.sendexpress模块的一部分而不是核心的一部分http module.