-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
32 lines (32 loc) · 1 KB
/
index.ts
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
import express,{Express,Request,Response} from 'express';
import mongoose,{ConnectOptions} from 'mongoose';
import dotenv from 'dotenv';
import authRouter from './auth/router';
import uploadHandler from './uploads/imageUploader';
import rateLimit, { RateLimitRequestHandler } from 'express-rate-limit';
dotenv.config();
const app:Express = express();
const port:number = 2000 || process.env.PORT ;
const limit:RateLimitRequestHandler = rateLimit({
windowMs: 15 * 60 * 1000,
max: 2,
message:"You have requested our Api many times.Wait! a moment",
headers:true
})
app.use(limit);
app.use(express.json());
app.use(express.urlencoded({extended:true}));
mongoose.connect(`${process.env.MONGODB_URI}`,{
useNewUrlParser:true,
useUnifiedTopology:true
}as ConnectOptions,(err)=>{
if(err)
console.log("Error connecting to the Database")
else
console.log("Db connected successfully");
})
app.use(authRouter);
app.use(uploadHandler);
app.listen(port,()=>{
console.log(`Server is running on ${port}`);
})