-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (34 loc) · 1003 Bytes
/
app.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
const express=require("express");
const morgan=require("morgan");
const createError=require("http-errors");
require('dotenv').config();
require('./helpers/init_mongodb')
const {verifyAccessToken}=require('./helpers/jwt_helper');
const AuthRoute=require('./routes/Authroute');
const app=express();
app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({extended:true}))
app.get('/',verifyAccessToken,async(req,res,next)=>{
res.send("hello from express servere")
})
app.use('/auth',AuthRoute)
app.use(async(req,res,next)=>{
//const error=new Error("not found");
// error.status=404
//next(error)
next(createError.NotFound('tHIS rOUTE IS NOT FOUND'));
})
app.use((err,req,res,next)=>{
res.status(err.status || 500)
res.send({
error:{
status:err.status||500,
message:err.message
}
})
})
const PORT=process.env.PORT||3000;
app.listen(PORT,()=>{
console.log(`SERVER RUNNING ON PORT ${PORT}`);
})