HN Singh
HN Singh

Reputation: 106

ExpressJS-Localhost not showing anything

This is my first time I am running ExpressJS. But the Localhost is not responding any data.Waiting for localhost keeps on appearing at left bottom corner. Also showing the terminal command

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

Answers (4)

Dhruv Jain
Dhruv Jain

Reputation: 1

As a beginner in Node.js and using express, localhost server might not working properly due to

  1. Either you didn't send any response through
app.get('/', (req, res) => { res.send('hello, get api') })
  1. Also, if you use middleware like app.use(express.json()), so if you didn't write json() and wrote simply json without braces, it stops the server to running

So, try to replace

app.use(express.json)

With

app.use(express.json())

Upvotes: -1

Rasheed
Rasheed

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

Rafael Echart
Rafael Echart

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

imjared
imjared

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

Related Questions