-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 1.1 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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const config = require('./config/config');
const url = config.bd_url;
const options = {
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 500,
poolSize: 5,
useUnifiedTopology: true,
useNewUrlParser: true
};
mongoose.connect(url, options);
mongoose.set('useCreateIndex', true);
mongoose.connection.on('connected', () => {
console.log('Aplicacão conectada ao banco de dados');
});
mongoose.connection.on('disconnected', () => {
console.log('Aplicacão desconectada do banco de dados');
});
mongoose.connection.on('error', err => {
console.log('Erro na conexão com o banco de dados', err);
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const indexRoute = require('./routes/index');
const usersRoute = require('./routes/users');
app.use('/', indexRoute);
app.use('/users', usersRoute);
const server = app.listen(3000);
console.log('Servidor Express iniciado na porta %s', server.address().port);
module.exports = app;