-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
36 lines (24 loc) · 796 Bytes
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const config = require('./config');
const authMiddleware = require('./middleware/auth');
const errorHandler = require('./middleware/error');
const routes = require('./routes');
const pkg = require('./package.json');
const { port, mongoUrl, secret } = config;
const app = express();
// Conectar aplicación a MongoDB
mongoose.connect(mongoUrl, { useNewUrlParser: true });
app.set('config', config);
app.set('pkg', pkg);
app.use(express.json());
app.use(authMiddleware(secret));
// Registrar rutas
routes(app, (err) => {
if (err) {
throw err;
}
// Registro de "middleware" que maneja posibles errores
app.use(errorHandler);
app.listen(port, () => console.log(`App listening on port ${port}`));
});