Skip to content

Instantly share code, notes, and snippets.

@StephanyBatista
Last active October 10, 2015 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephanyBatista/8e181440070fe8222410 to your computer and use it in GitHub Desktop.
Save StephanyBatista/8e181440070fe8222410 to your computer and use it in GitHub Desktop.
How create a server web with routes
var http = require('http');
var atendeRequisicao = function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
if(request.url == '/')
response.write("<h1>Home</h1>");
else if(request.url == '/sobre')
response.write("<h1>Sobre</h1>");
else if(request.url == '/contato')
response.write("<h1>Contato</h1>");
else
response.write("<h1>Error</h1>");
response.end();
}
var server = http.createServer(atendeRequisicao);
var servidorLigou = function() {
console.log('Servidor Hello World rodando!');
}
server.listen(3000, servidorLigou);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment