无法使用http和express模块连接到nodejs中的localhost
我在nodejs中编写以下内容并运行它。但无法连接到 localhost:8080。我正在使用 http 和express 模块。
const http=require('http');
const PORT=process.env.PORT || 8080;
const express=require('express');
const app=express();
http.createServer((req,res)=>{
res.end('Hellow world')
}).listen(PORT);
或者
app.listen(PORT);
app.use('/',(req,res)=>{
res.send("Hellow world");
});
I write following in nodejs and run it. but can not connect to localhost:8080. I am use http and express module.
const http=require('http');
const PORT=process.env.PORT || 8080;
const express=require('express');
const app=express();
http.createServer((req,res)=>{
res.end('Hellow world')
}).listen(PORT);
or
app.listen(PORT);
app.use('/',(req,res)=>{
res.send("Hellow world");
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我在我的电脑上运行它时,它工作正常。
可能是这样:
http://localhost:8080
"localhost"
将其更改为:您能放一张确切错误或屏幕的图片吗?重新看到?
When I run it on my pc it works fine.
It could be that:
http://localhost:8080
"localhost"
beside PORT to change it to:Could you put a picture of the exact error or screen you're seeing?