-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (28 loc) · 1.04 KB
/
app.js
File metadata and controls
32 lines (28 loc) · 1.04 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
28
29
30
31
32
const express=require('express')
const morgan=require('morgan')
const cors=require('cors');
const userRoute=require('./router/user.route')
const bookROute=require('./router/book.route')
const {pageNotFound,ErrorCghout}=require('./middlewares/handleErrors')
// process.env ומכניס את ערכיו לתוך .env קורא את כל התוכן מהקובץ
require('dotenv').config();
// חיבור למסד נתונים
require('./config/db')
const app=express();
app.use(express.json()) // אם שולחים אוביקט מהקליינט
app.use(express.urlencoded({ extended: true })) // אם שולחים קבצים מהקליינט
app.use(morgan('dev'));//printing the information of the request
app.use(cors())//enable access to all api's addresses
app.use('/user',userRoute)
app.use('/book',bookROute)
//none existing url
app.use(pageNotFound)
//when error acur
app.use(ErrorCghout)
app.get("/", (req, res) => {
res.send("wellcome");
});
const port=process.env.PORT;
app.listen(port,()=>{
console.log(`listening on http://localhost:${port}`);
})