-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (26 loc) · 950 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Get the packages we need
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
// Connect to the MongoDB
mongoose.connect('mongodb://localhost:27017/KnowledgeBase');
// Create Express application
var app = module.exports = express();
var NODE_ENV = 'development';
//Set Variables
app.set('env', process.env.NODE_ENV || 'production');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
routes = require('./routes/index')
app.use('/api', routes);
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'example.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
// Use environment defined port or 4000
var port = process.env.PORT || 4000;
// Start the server
app.listen(port);
console.log('App Running on port ' + port);