【发布时间】:2019-07-15 23:37:42
【问题描述】:
我是 node.js 的新手,我想知道一般测试以下类型代码的最佳方法。现在,我将这一切作为 netbeans node.js 项目中的一个文件来完成。我没有得到任何输出,输出应该是“HELLO SERVER”。
它通常编译没有错误,但没有输出,其他时候它说
"throw er; // 未处理的 'error' 事件 Error: listen EADDRINUSE :::8000"
我已经知道这个拒绝意味着什么,我认为当我点击两次运行时它就是这样做的,因为那个端口被第一次运行占用了。
我已经尝试了多个端口,它可以工作但没有输出......
我应该以其他方式对此进行测试吗?为什么没有输出?输出应该是“HELLO SERVER” 谢谢。
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
request.on("data", function (chunk) {
response.write(chunk.toString().toUpperCase());
});
request.on("end", function () {
response.end();
});
}).listen(8000);
var http = require("http");
var request = http.request({
hostname: "localhost",
port: 8000,
method: "POST"
}, function (response) {
response.on("data", function (chunk) {
process.stdout.write(chunk.toString());
});
});
request.end("Hello Server");
【问题讨论】:
标签: javascript node.js