-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (40 loc) · 1.21 KB
/
index.js
File metadata and controls
53 lines (40 loc) · 1.21 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express')
const app=express()
const dotenv= require('dotenv').config()
const PORT=process.env.PORT|| 3000
const connect= require('./config/dbConnect')
const userRouter= require('./routes/users/userRoutes')
const postRouter=require('./routes/posts/postRoutes')
const commentRouter=require('./routes/comments/commentRoutes')
const categoryRouter=require('./routes/categories/categoryRoutes')
const globalErrHandler = require('./middlewares/globalErrHandler')
const isAdmin = require('./middlewares/isAdmin')
//middlewares
app.use(express.json()) //to pass incoming payload (from req.body)
//Home Route
app.get('/',async(req,res)=>{
try{
const posts= await Post.find()
res.json({
status:"Success",
data:posts,
})
}
catch (error){
res.json(error)
}
})
//users route
app.use('/app/v1/users/',userRouter)
//posts route
app.use('/app/v1/posts/',postRouter)
//comments route
app.use('/app/v1/comments',commentRouter)
//categories route
app.use('/app/v1/categories',categoryRouter)
//error hander middleware
app.use(globalErrHandler)
app.listen(PORT,()=>{
console.log('server is up and running....')
console.log("nodeon testing")
})