简体   繁体   中英

ExpressJS-Localhost not showing anything

This is my first time I am running ExpressJS. But the Localhost is not responding any data. 等待 localhost 不断出现在左下角。还显示终端命令

Below is the Code I have written

 const express=require('express'); const app=express(); app.get('/',(req,res)=> { }); app.listen(3000,()=>console.log("running at 3000 port"));

I have tried to change the localhost to 4000,5000.But same error.

Additional Information: Running on Ubuntu 16.10

Any clue of whats happening over here?

You're not giving the browser anything to render. Try following the Hello World example in the docs and you might be pleasantly surprised:

https://expressjs.com/en/starter/hello-world.html

I dont know if you still need an answer but i think i might have it.

I had the same issue with the 'app.use(express.json)'

when i deleted my server started working, it was because we were writing it work it actually is

'app.use(express.json())'

PD: that command works for telling EXPRESS that it has to read a json file or request...

i hope this can help you out

Just to add to imjared's answer.. Always, response has to be sent back to the client(Browser) for any new page you create because that's what will be displayed on the browser. Adding res.send("some data") in the function will resolve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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