revisionfour
8/6/2013 - 2:53 AM

Simple template for starting an express project

Simple template for starting an express project

var express = require('express')
  , http = require('http');

var app = express();

require('./config/init-express')(express, app);

var server = http.createServer(app);

server.listen(app.get('port'), function(){
	console.log('Server listening on port ' + app.get('port'));
});
// Main routing for express app

module.exports = function(express, app){
  app.get('/',function(req, res){
		res.sendfile('public/index.html');
	});
}
<!DOCTYPE html>
<html>
  <head>
    <title></title>
 
    <!-- Favicon -->
    <link rel="icon" type="image/png" href="/images/favicon.png">
 
    <!-- Main stylesheet for the web application -->
    <link rel="stylesheet" type="text/css" href="/stylesheets/app.css" />
 
    <!-- jQuery -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  </head>
  <body>
    
 
    <!-- Main JS for web application -->
    <script type="text/javascript" src="/javascripts/app.js"></script>
  </body>
</html>
// Express configuration

module.exports = function(express, app){
  app.set('port', process.env.PORT || 3000);
	app.use(express.favicon());
	app.use(express.logger('dev'));
	app.use(express.bodyParser());
	app.use(express.methodOverride());
	app.use(app.router);

	app.use(express.static(__dirname.replace('config','public')));

	// development only
	if ('development' == app.get('env')) {
	  app.use(express.errorHandler());
	}
};