Reputation: 106
This is my first time I am running ExpressJS. But the Localhost is not responding any data.
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?
Upvotes: 2
Views: 7729
Reputation: 1
As a beginner in Node.js and using express, localhost server might not working properly due to
app.get('/', (req, res) => { res.send('hello, get api') })
app.use(express.json())
, so if you didn't write json() and wrote simply json without braces, it stops the server to runningSo, try to replace
app.use(express.json)
With
app.use(express.json())
Upvotes: -1
Reputation: 1
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.
Upvotes: 0
Reputation: 51
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
Upvotes: 5
Reputation: 20554
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
Upvotes: 3