NODE.JS server does not run

Asked

Viewed 52 times

0

I’m starting to study Ode now, and I’m already facing this problem. Follow the code:

var http = require('http')
http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'Text/plain'})
  res.end('Sou um servidor criado pelo Node.js!')
}).listen(3000, '127.0.0.1')

When I run "Node Node-server" on the terminal nothing happens. There is some error in the code?

1 answer

0


This is the expected behavior. To see the server working, open the browser and type in the address bar 127.0.0.1:3000.

The console will only display something if a call is made from console.log.

var http = require('http')
http.createServer(function(req, res) {
   console.log('requisição recebida')
   res.writeHead(200, {'Content-Type': 'Text/plain'})
   res.end('Sou um servidor criado pelo Node.js!')
}).listen(3000, '127.0.0.1', () => console.log('servidor rodando'))

Browser other questions tagged

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