-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·45 lines (34 loc) · 1.17 KB
/
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
36
37
38
39
40
41
42
43
44
45
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
methodOverride = require("method-override"),
mongoose = require('mongoose');
// Enable huge json files
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
// Connection to DB
mongoose.connect('mongodb://localhost/techo-cache', function(err, res) {
if(err) throw err;
console.log('Connected to Database');
});
// Middlewares
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
// Import Models and controllers
var models = require('./models/survey')(app, mongoose);
var SurveyCtrl = require('./controllers/surveyController');
// API routes
var surveys = express.Router();
surveys.route('/construct')
.get(SurveyCtrl.findAllSurveys)
.post(SurveyCtrl.addSurvey);
surveys.route('/construct/:id')
.get(SurveyCtrl.findById)
.put(SurveyCtrl.updateSurvey)
.delete(SurveyCtrl.deleteSurvey);
app.use('/api', surveys);
// Start server
app.listen(3000, function() {
console.log("Node server running on http://localhost:3000");
});