Created
January 11, 2016 16:28
-
-
Save StephanyBatista/87bae4e99b2e4c1621ac to your computer and use it in GitHub Desktop.
How create a server web with routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var newRequest = 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>About</h1>"); | |
else if(request.url == '/contato') | |
response.write("<h1>Contact</h1>"); | |
else | |
response.write("<h1>Error</h1>"); | |
response.end(); | |
} | |
var server = http.createServer(newRequest); | |
var serverOn = function() { | |
console.log('Servidor Hello World rodando!'); | |
} | |
server.listen(3000, serverOn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment