Skip to content

Instantly share code, notes, and snippets.

@jaeschrich
Created August 6, 2012 20:00
Show Gist options
  • Save jaeschrich/3277994 to your computer and use it in GitHub Desktop.
Save jaeschrich/3277994 to your computer and use it in GitHub Desktop.
Node.js project boilerplate.
<!DOCTYPE html>
<html lang="en"> <!-- based on HTML5 Boilerplate and Twitter Bootstrap starter template -->
<head>
<!-- You should probably use a local version of html5shim here. -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Envy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
404: Not found. Sorry :(
</body>
</html>
<!DOCTYPE html>
<html lang="en"> <!-- based on HTML5 Boilerplate and Twitter Bootstrap starter template -->
<head>
<!-- You should probably use a local version of html5shim here. -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Envy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
Hello World
</body>
</html>
var http = require("http")
var fs = require('fs')
var url = require('url')
http.createServer(function(req, res){
console.log("Request for "+req.url+"recieved.")
var path = url.parse(req.url).pathname
switch(path){
case '/':
fs.readFile('index.html', function(err, data){
if (err){console.log(err)}
res.writeHead(200, {"Content-Type": 'text/html'})
res.end(data)
})
break;
default:
fs.readFile('404.html', function(err, data){
if (err){console.log(err)}
res.writeHead(200, {"Content-Type": 'text/html'})
res.end(data)
console.log("404 error for "+req.url)
})
break;
}
}).listen(8080)
console.log("Server Started")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment