You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 17:10:25