-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (38 loc) · 1.19 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
35
36
37
38
39
40
41
42
43
44
45
46
// dotenv is a module that loads environment varibles from a .env file into process.env
require('dotenv').config();
// framework
const express = require('express');
// initializing express
const app = express();
// database
// const db = require('./database/index')
const mongoose = require('mongoose');
// mongodb is schemaless but mongoose is not schemaless, helps in validation part
// establish connection
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}).then( ()=>
console.log("Database connected 🤩🤩🤩")
).catch ((err)=>
console.log(err.message)
)
// configurations
app.use(express.json());
// importing bookRoutes, authorRoutes, publicationRoutes
const bookRoutes = require('./API/Book');
const authorRoutes = require('./API/Author');
const publicationRoutes = require('./API/Publication');
// initialize microservices
app.use("/book",bookRoutes) // using prefix
app.use("/author",authorRoutes);
app.use("/publication",publicationRoutes);
app.get('/',(req,res)=>{
res.send("BOOK MANAGEMENT API");
})
// listening
app.listen(3080, ()=>{
console.log("Server started at 3080...");
})