-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (28 loc) · 854 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
import express from 'express'
import morgan from "morgan";
import cors from "cors";
import mongoose from 'mongoose';
import dotenv from "dotenv";
import ContactusRouter from './routes/sendgrid-route.js';
import userRouter from './routes/user-route.js';
const app = express();
dotenv.config();
app.use(express.json());
app.use(cors({
origin:"http://localhost:7500",
methods:['GET','POST'],
credentials:true,
}))
const DB=process.env.MONGO_DB_URL.replace('<password>',process.env.MONGO_PASSWORD);
mongoose.connect(DB).then(()=>{
console.log('Database is connected✌️');
});
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
app.use('/api',ContactusRouter);
app.use('/api/v1',userRouter);
const port = process.env.PORT || 7500;
app.listen(port, () => {
console.log(`Server is running on PORT ${port}🎉`);
});