Skip to content

Commit

Permalink
express3 -> 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-lin committed Sep 18, 2014
1 parent b211828 commit fe54403
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
50 changes: 29 additions & 21 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,49 @@
// mongoose setup
require( './db' );

var express = require( 'express' );
var routes = require( './routes' );
var http = require( 'http' );
var path = require( 'path' );
var app = express();
var engine = require( 'ejs-locals' );
var express = require( 'express' );
var http = require( 'http' );
var path = require( 'path' );
var engine = require( 'ejs-locals' );
var favicon = require( 'serve-favicon' );
var cookieParser = require( 'cookie-parser' );
var bodyParser = require( 'body-parser' );
var methodOverride = require( 'method-override' );
var logger = require( 'morgan' );
var errorHandler = require( 'errorhandler' );
var static = require( 'serve-static' );

var app = express();
var routes = require( './routes' );


// all environments
app.set( 'port', process.env.PORT || 3001 );
app.engine( 'ejs', engine );
app.set( 'views', path.join( __dirname, 'views' ));
app.set( 'view engine', 'ejs' );
app.use( express.favicon());
app.use( express.logger( 'dev' ));
app.use( express.cookieParser());
app.use( express.bodyParser());
app.use( express.json());
app.use( express.urlencoded());
app.use( express.methodOverride());
app.use( routes.current_user );
app.use( app.router );
app.use( express.static( path.join( __dirname, 'public' )));

// development only
if( 'development' == app.get( 'env' )){
app.use( express.errorHandler());
}
app.use( favicon( __dirname + '/public/favicon.ico' ));
app.use( logger( 'dev' ));
app.use( methodOverride());
app.use( cookieParser());
app.use( bodyParser.json());
app.use( bodyParser.urlencoded({ extended: true }));

// Routes
app.use( routes.current_user );
app.get( '/', routes.index );
app.post( '/create', routes.create );
app.get( '/destroy/:id', routes.destroy );
app.get( '/edit/:id', routes.edit );
app.post( '/update/:id', routes.update );

app.use( static( path.join( __dirname, 'public' )));

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

http.createServer( app ).listen( app.get( 'port' ), function (){
console.log( 'Express server listening on port ' + app.get( 'port' ));
});
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
"version" : "0.0.1",
"private" : true,
"dependencies" : {
"express" : "3.4.7",
"ejs" : "0.8.5",
"ejs-locals" : "1.0.2",
"mongoose" : "3.8.1"
"body-parser" : "1.8.2",
"cookie-parser" : "1.3.3",
"express" : "4.9.2",
"ejs" : "1.0.0",
"errorhandler" : "1.2.0",
"method-override" : "2.2.0",
"ejs-locals" : "1.0.2",
"mongoose" : "3.8.16",
"morgan" : "1.3.1",
"serve-favicon" : "2.1.4",
"serve-static" : "1.6.2"
}
}
Binary file added public/favicon.ico
Binary file not shown.

0 comments on commit fe54403

Please sign in to comment.