-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (48 loc) · 1.46 KB
/
index.js
File metadata and controls
65 lines (48 loc) · 1.46 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
54
55
56
57
58
59
60
61
62
63
64
65
import express from "express";
import cookieParser from "cookie-parser";
import cors from 'cors';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import authRoutes from './routes/authRoutes.js';
import userRoutes from './routes/userRoutes.js';
import doctorRoutes from './routes/doctorRoutes.js';
import reviewRoutes from './routes/reviewRoutes.js';
// import crypto from 'crypto';
// const randomBytes = crypto.randomBytes(256).toString('base64');
// console.log(randomBytes);
dotenv.config();
const app = express();
const MONGODB_URL = process.env.MONGODB_URL
const port = process.env.PORT || 8000
const corsOptions = {
origin: true
}
// middlewares
app.use(express.json());
app.use(cors(corsOptions));
app.use(cookieParser())
app.use('/api/v1/auth', authRoutes)
app.use('/api/v1/user', userRoutes);
app.use('/api/v1/doctor', doctorRoutes);
app.use('/api/v1/review', reviewRoutes);
app.get('/', (req, res)=> {
res.send('Api is working')
})
// database connection
mongoose.set('strictQuery', false);
const connectDb = async() => {
try{
await mongoose.connect(MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
console.log('Mongodb is connected!!');
}
catch(err){
console.log('Mongodb connection is a failure :( ');
}
}
app.listen(port, () => {
connectDb();
console.log(`App is listening on port ${port}`);
})