Node.js Hello World程序无法在localhost显示,请求解决运行问题
Express服务启动正常,但localhost页面无法显示内容
我编写了基于Express框架的Node.js代码如下:
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
启动程序后CMD显示正常,能看到服务监听端口的日志输出,但访问localhost:3000时页面无法显示"Hello World"内容,浏览器提示无法连接。
- CMD截图情况:命令行执行启动命令后无报错,成功输出
Example app listening on port 3000 - 浏览器截图情况:页面提示“无法访问此网站,localhost拒绝了连接请求”
希望排查问题,让服务正常运行并在页面看到预期输出。
内容的提问来源于stack exchange,提问作者Sujith Julakanti
相关产品推荐
相关产品推荐

