-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (21 loc) · 792 Bytes
/
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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
require('dotenv/config');
// Middlewares
app.use(bodyParser.json()); // All the body requests will be converted to json
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_CONNECTION,
{ useNewUrlParser: true, useUnifiedTopology: true },
(result) => {
console.log(process.env.MONGODB_CONNECTION);
console.log(result);
}
);
// Import Routes
const postsRoute = require('./routes/posts');
// Middlewares
app.use('/posts', postsRoute); // All the routes started with /posts will be handled by postsRoute
// Listenning
app.listen(3000);