Skip to content

Instantly share code, notes, and snippets.

@addisaden
Last active August 29, 2015 13:56
Show Gist options
  • Save addisaden/9089579 to your computer and use it in GitHub Desktop.
Save addisaden/9089579 to your computer and use it in GitHub Desktop.
var fs = require("fs");
var http = require("http");
http.createServer(function (req, res) {
var current_path = "." + req.url;
if(req.url === "/") current_path = "./index.html";
fs.exists(current_path, function(exists) {
if(exists) {
fs.stat(current_path, function(err, stats) {
if(stats.isFile()) {
fs.createReadStream(current_path).pipe(res);
} else {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("Path is not a file.");
}
});
} else {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("Path does not exists.");
}
});
}).listen(3000);
console.log("Server is listening on port 3000");
console.log("Server has content of " + process.cwd());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment