-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (33 loc) · 1.05 KB
/
server.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
46
47
// load necessary modules
var express = require('express');
var app = express();
var cors = require('cors')
var path = require('path');
var bodyParser = require('body-parser');
var MongoClient = require('mongodb').MongoClient;
var db;
// app CONFIGURATION
var config = require('./config');
// use body parser so we can grab information from POST requests
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// set the public folder to serve public assets
app.use(express.static(__dirname + '/public'));
app.use(cors());
// api
// API routes
var apiRoutes= require('./app/api');
app.use('/api', apiRoutes);
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/public/app/views/index.html'));
});
// Database connection
MongoClient.connect(config.database, function(err, database) {
if (err) return console.log(err)
db = database;
console.log('me conecte bien a la base de datos de no crime');
module.exports.database = db;
app.listen(config.port, function(){
console.log('listening on 1337')
})
});