-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (36 loc) · 1.1 KB
/
Copy pathserver.js
File metadata and controls
47 lines (36 loc) · 1.1 KB
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
46
47
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var config = require('./config');
var app = express();
mongoose.connect(config.database,function(err){
if(err)
console.log(err);
else
console.log("Connected to the database");
});
/*
* body-parser is a piece of express middleware that
* reads a form's input and stores it as a javascript
* object accessible through `req.body`
* body-parser will be used for all the routes coming to this app
*
*/
////////////Global Middleware/////////////
app.use(bodyParser.urlencoded({extended : true})); //extended : false means only String can be parsed in the encoded url
app.use(bodyParser.json());
app.use(morgan('dev'));
var api = require('./app/routes/api')(app,express);
app.use('/api',api); // /api is the prefix used before each APIs
app.get('*',function(req,res){
res.sendFile(__dirname + '/public/views/index.html');
});
app.listen(config.port,function(err){
if(err){
console.log(err);
}
else{
console.log("Listening");
}
});