My localhost connection is taking too long

Asked

Viewed 524 times

0

I created a Nodejs server with express but when I try to access http://localhost:3000 the page never loads, is loading only.

const http = require('http')

const express = require('express')

http.createServer(express).listen(3000, () => console.log("Servidor rodando local na porta 3000"));
  • You probably have a middleware that doesn’t call the function next. It would be interesting you edit the question by putting your current code so that we can help you better

2 answers

1

do not use http, since you are using express

thus

const express = require("express");
const app = express();

app.listen(3000,()=> console.log("Servidor online");
  • Why not use http? Not a good thing?

  • It’s not much about not being good, but not making much sense, using http when using express, because express already does everything that html does

  • Sorry, but I did not understand the relationship of Express with HTML, in this case

0


Following the official documentation of express we should no longer use the http module of the standard nodejs libraries, because if you pay attention to the code app.listen, all he does is create a http.createServer() and calls the listen() for him, that is, using the new express mode just shortens his time and helps him not have to use the http module directly.

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

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.