summaryrefslogtreecommitdiff
path: root/week-7/Final4/blog/app.js
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-02-20 21:47:20 -0700
committermo khan <mo@mokhan.ca>2015-02-20 21:47:20 -0700
commitfe7e28edee40691d8b1189769a9b1b9939686d77 (patch)
treea8a57e33369da7f4d6b5267c082fd6644974686f /week-7/Final4/blog/app.js
parentbd663082a8b29b02a98b52fe384cfbde18bedf73 (diff)
add final 3 and 4 validation scripts.
Diffstat (limited to 'week-7/Final4/blog/app.js')
-rw-r--r--week-7/Final4/blog/app.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/week-7/Final4/blog/app.js b/week-7/Final4/blog/app.js
new file mode 100644
index 0000000..f773876
--- /dev/null
+++ b/week-7/Final4/blog/app.js
@@ -0,0 +1,27 @@
+var express = require('express')
+ , app = express() // Web framework to handle routing requests
+ , cons = require('consolidate') // Templating library adapter for Express
+ , MongoClient = require('mongodb').MongoClient // Driver for connecting to MongoDB
+ , routes = require('./routes'); // Routes for our application
+
+MongoClient.connect('mongodb://localhost:27017/blog', function(err, db) {
+ "use strict";
+ if(err) throw err;
+
+ // Register our templating engine
+ app.engine('html', cons.swig);
+ app.set('view engine', 'html');
+ app.set('views', __dirname + '/views');
+
+ // Express middleware to populate 'req.cookies' so we can access cookies
+ app.use(express.cookieParser());
+
+ // Express middleware to populate 'req.body' so we can access POST variables
+ app.use(express.bodyParser());
+
+ // Application routes
+ routes(app, db);
+
+ app.listen(3000);
+ console.log('Express server listening on port 3000');
+});