Last active
August 31, 2016 02:39
-
-
Save itgelo/16865ede3a14bab694ffe5d31cbc7ad4 to your computer and use it in GitHub Desktop.
Nodejs Basic Route
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"); | |
http.createServer(function(req, res){ | |
var getUri = req.url; | |
var code = ""; | |
var template = ""; | |
if(getUri != "/favicon.ico"){ | |
if(getUri == "/"){ | |
code = 200; | |
template = "Index page"; | |
}else if(getUri == "/profile") { | |
code = 200; | |
template = "Page " + getUri; | |
}else { | |
code = 404; | |
template = "Page not found!"; | |
} | |
} | |
res.writeHead(code, {"Content-Type":"text/plain"}); | |
res.end(template); | |
}).listen(3000); | |
console.log("Server is running ..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment