简体   繁体   English

为什么我不能在localhost:3000上查看我的Express应用程序

[英]Why can I not view my express app on localhost:3000

I am trying to run an express app and view the res.send message on localhost:3000 as instructed in the course I am viewing. 我正在尝试运行Express应用,并按照我正在查看的课程中的说明在localhost:3000上查看res.send消息。 app.js app.js

 let express = require("express"); let app = express(); app.get("/",function(req,res){ res.send("Hello World"); }); app.listen(3000,function(){ console.log("listening on port 3000"); }); 

And then in the terminal I type node app.js to run the file. 然后在终端中,键入node app.js来运行文件。 app.listen works just fine displaying the "listening on port 3000" message on the terminal. app.listen可以在终端上显示“正在侦听端口3000”消息,效果很好。 I then go to my browser and try http://localhost:3000 and nothing loads, tried just localhost:3000 and again nothing loads. 然后,我进入浏览器并尝试http:// localhost:3000 ,没有任何负载,仅尝试了localhost:3000,再次没有负载。 I have no idea why this is happening at all, could someone please help me. 我完全不知道为什么会这样,有人可以帮我吗。

You created local server, you will see the text if for example send get request via PostMan etc. 您创建了本地服务器,如果例如通过PostMan发送get请求等,您将看到文本。

or another way it sends html file to client, you'll see it immediately, more details here 或以其他方式将html文件发送到客户端,您将立即看到它,更多详细信息在这里

I have tried your code in my system and it works! 我已经在系统中尝试过您的代码,并且可以正常工作! I think the issue may be with your browser, try it in a different browser or in a private mode. 我认为问题可能出在您的浏览器上,请在其他浏览器或专用模式下尝试。 If the issue persists you could try it in a different port. 如果问题仍然存在,则可以在其他端口中尝试。 Also make sure that you are running the latest versions of Node and Express. 还要确保您正在运行最新版本的Node and Express。

Resources: MDN EJS 资源: MDN EJS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM