nodejs调试报错“ReferenceError: require is not defined”,为什么?

dannyportmantdlemon1900
  • 240
function onRequest(request, response, modules) {
 var a = require('http');
a.createServer(function (req, res) {
  req.setEncoding('utf8');
  var postData = "";
  req.addListener("data", function (chunk) {
    postData += chunk;
  });
  req.addListener("end", function () {
    var resp = function (ret, status_code) {
      res.writeHead(status_code, {
        "Content-Type": "text/plain; charset=utf-8"
      });
      res.end(ret);
    }
    
  });
}).listen(8080, "0.0.0.0");
}                  

                     
回复
阅读 20.5k
2 个回答
yuhualingfeng
  • 1.7k

1.使用了未定义的函数
2.代码不太全,看错误提示,找出错误行,然后仔细的核对

宣传栏