Created
October 19, 2015 16:39
-
-
Save chanakaDe/fa66f54918dbc46577b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var bodyParser = require("body-parser"); | |
var morgan = require("morgan"); | |
var config = require("./config"); | |
var mongoose = require("mongoose"); | |
var cors = require('cors'); | |
var app = express(); | |
/** | |
* Using CORS to reduce CROSS Origine. | |
*/ | |
app.use(cors()); | |
/** | |
* Connecting to MongoDB using Mongoose. | |
*/ | |
mongoose.connect(config.database, function (err) { | |
if (err) { | |
console.error(err); | |
} else { | |
console.log("Connected to database"); | |
} | |
}); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.use(bodyParser.json()); | |
app.use(morgan('dev')); | |
var api = require('./app/routes/api')(app, express); | |
app.use('/api', api); | |
app.listen(config.port, function (err) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log("Listening on port 3000"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment