Skip to content

Instantly share code, notes, and snippets.

@itgelo
Last active August 31, 2016 02:39
Show Gist options
  • Save itgelo/16865ede3a14bab694ffe5d31cbc7ad4 to your computer and use it in GitHub Desktop.
Save itgelo/16865ede3a14bab694ffe5d31cbc7ad4 to your computer and use it in GitHub Desktop.
Nodejs Basic Route
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