-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (35 loc) · 1.49 KB
/
Copy pathserver.js
File metadata and controls
50 lines (35 loc) · 1.49 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
48
// Dependencies
// -----------------------------------------------------
const
express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
Mongoose = require('mongoose');
// Globals
// -----------------------------------------------------
const
app = express(),
MongoDB = Mongoose.connection,
MONGO_CONN_STRING = process.env.MONGO_CONN_STRING || 'mongodb://172.16.11.145:27017';
// Express Configuration
// -----------------------------------------------------
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.urlencoded({extended: true})); // parse application/x-www-form-urlencoded
app.use(cors()); // Enable CORS
// Starts MongoDB connection
// -----------------------------------------------------
MongoDB.on('error', (error) => {
console.log('Connection to MongoDB failed! =(');
console.error(error);
} );
MongoDB.once('open', () => {
console.log('Connection to MongoDB stablished!');
// Routes
// ------------------------------------------------------
require('./routes/agentes.js')(app);
require('./routes/servicios.js')(app);
// Server start
// -----------------------------------------------------
app.listen(1337, () => console.log('Backend listening on port 1337!') );
});
Mongoose.connect(MONGO_CONN_STRING, {});