-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 1.05 KB
/
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
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const blogRouter = require('./blog.router');
// Pour récupérer les données
const bodyParser = require('body-parser');
app.set('view engine', 'pug');
app.set('views', './views');
const PORT = 9000;
const HOST = 'localhost';
app.use('/', blogRouter);
app.use(express.static('./public'));
app.use(bodyParser.urlencoded({extended: false}));
// Démarrage application
const options = {
useNewUrlParser: true,
useUnifiedTopology: true
};
mongoose.connect(`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}/${process.env.DB_NAME}?retryWrites=true&w=majority`, options)
.then(() => console.log(`Mongoose : Connexion établie à Atlas !`))
.then(() => {
app.listen(PORT, HOST, () => {
console.log(`Express : Le serveur écoute sur http://${HOST}:${PORT}`);
});
})
.catch((err) => console.log(err));