-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
31 lines (23 loc) · 856 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
require('dotenv').config();
const exepress = require("express");
const router = exepress.Router();
const mongoose = require("mongoose");
const articles = require("./routes/article.routes");
const bodyParser = require("body-parser");
const app = exepress();
const port = 8000;
mongoose.connect(process.env.mongoURI, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
.then(res => console.log(`Connection Succesful ${res}`))
.catch(err => console.log(`Error in DB connection ${err}`));
//body-parser config;
app.use(exepress.json())
app.use(bodyParser.urlencoded({extended: true }));
app.use(bodyParser.json())
app.get("/", (req, res) => {
res.send(`<h1>Hello!</h1>`)
})
app.listen(port, () => {
console.log(`Application is listening at port ${port}`);
})
//register the enpoint
app.use("/api/v1/articles", articles);