summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..329f86f
--- /dev/null
+++ b/index.js
@@ -0,0 +1,36 @@
+
+var express = require('express');
+var mongoose = require('mongoose');
+var bodyParser = require('body-parser');
+var methodOverride = require('method-override');
+
+// create express application
+var app = express();
+var port = 3000;
+
+// setup REST middleware
+app.use(bodyParser.urlencoded({extended: true}));
+app.use(bodyParser.json());
+app.use(methodOverride('X-HTTP-Method-Override'));
+
+// CORS support
+app.use(function(req, res, next) {
+ res.header('Access-Control-Allow-Origin', '*');
+ res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
+ res.header('Access-Control-Allow-Headers', 'Content-Type');
+ next();
+});
+
+// hello
+app.use('/hello', function(req, res, next) {
+ res.send('Hello World');
+ next();
+});
+
+// connect to mongodb
+mongoose.connect('mongodb://localhost/meanapp');
+mongoose.connection.once('open', function() {
+ console.log("listening on port " + port);
+ app.listen(port);
+});
+