gpt4 book ai didi

node.js - Nodejs 服务器创建未运行

转载 作者:可可西里 更新时间:2023-11-01 11:12:09 25 4
gpt4 key购买 nike

我是 nodejs 的新手。我发现这个服务器创建程序很困难

var http =  require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}

http.createServer(onRequest).listen();

最佳答案

你必须提到要监听的端口号。

您的代码必须在监听中有一个端口号。

http.createServer(onRequest).listen(8080);

端口号8080已经被占用....所以我用

另一个端口号,例如 8083....它可以工作...

关于node.js - Nodejs 服务器创建未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20240792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com