-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (19 loc) · 1.05 KB
/
index.js
File metadata and controls
27 lines (19 loc) · 1.05 KB
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
const env = require("dotenv/config");
const express = require("express");
const app = express();
const bookrouter = require("./Routes/book.routes");
const authorRouter = require("./Routes/author.routes");
const { loger } = require("./middleware/loger");
const PORT = 8000;
//in memory database this is violating the rule which is the stateless means that in the stateless you can not create the data inside the memory(server) you have create outside the memory and that is database which called stateless but here donot use the database
//middlewares (plugins)
app.use(express.json());
// what it will do if some data comes from the frontend and it has header that is application/json and it will do all the transformation for me and give me actual data in the request .body
//custom middlewares
app.use(loger);
//Routes
app.use("/books", bookrouter); // if there is any routes which starts with/books move(delegate) that request to bookrouter
app.use("/author", authorRouter);
app.listen(PORT, () => {
console.log(`HTTP server is running on PORT number ${PORT}`);
});