最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - JavaScript Node js `res.send is not a function error` - Stack Overflow

programmeradmin0浏览0评论
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

Share Improve this question asked Mar 30, 2018 at 9:14 Bugs BuggyBugs Buggy 1,54619 silver badges42 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论