Skip to content

Instantly share code, notes, and snippets.

@ryansobol
Last active August 29, 2015 14:17
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 ryansobol/3f86ee63034e321c14d4 to your computer and use it in GitHub Desktop.
Save ryansobol/3f86ee63034e321c14d4 to your computer and use it in GitHub Desktop.
// Load required module
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer(function(request, response) {
var pathname = __dirname + url.parse(request.url).pathname;
fs.exists(pathname, function(exists) {
if (exists) {
fs.readFile('index.html', function(err, content) {
response.end(content);
});
} else {
response.writeHead(404, { "Content-Type": "text/html" });
response.end("<h1>404 File Not Found</h1>");
}
});
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment