【问题标题】:My lost host server is running in cmd but in browser it is showing localhost didn't send any data我丢失的主机服务器在 cmd 中运行,但在浏览器中显示 localhost 没有发送任何数据
【发布时间】:2020-04-26 19:27:45
【问题描述】:

hyper terminal

my local server 代码是:

const express = require('express');
const app = express();
const port = 3000;

app.use("/",(request ,res)=> res.end("Hello World"));
app.listen(port , ()=>{
    console.log("server is at 3000");
});

【问题讨论】:

  • res.send,而不是 res.end.
  • end 方法的文档建议在发送数据时使用其他方法,但它仍然可以工作:expressjs.com/en/api.html#res.end。如果你卷曲那个端点,你会看到什么?
  • 我认为上面的代码运行良好。确保你得到了 url:localhost:3000/,你就会得到结果。

标签: node.js express networking localhost node-modules


【解决方案1】:

您好像漏掉了res.send

app.use("/", (request ,res) => res.send("Hello World"));

【讨论】:

  • 没什么区别
  • 如何向服务器发送请求?打开浏览器并在地址栏中输入localhost:3000。您应该从服务器看到 hello world。
  • 您确定您正在运行正确的应用程序吗?附带服务器日志的屏幕截图中的输出应为server is at 3000
  • 是相同的代码,我只是在发布之前进行了此更改,其余完全相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-27
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 2016-09-28
相关资源
最近更新 更多