-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.02 KB
/
index.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
import express from 'express';
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import cors from 'cors';
// import routes
import cookieParser from 'cookie-parser';
import userRouter from './routes/user.js';
import videoRouter from './routes/videos.js';
// import dashboard monitor
require('./analytics/sharpdash');
dotenv.config();
const { PORT, DB_CONNECT } = process.env;
const app = express();
// Connect to MongoDB Atlas
mongoose.connect(
DB_CONNECT,
{ useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false },
() => {
console.log('Connected to MongoDB 📖');
}
);
// Middlewares
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cookieParser());
app.use(cors());
// app.use(
// cors({
// origin: 'http://localhost:3000',
// credentials: true,
// })
// );
// Route middlewares
app.use('/api/user', userRouter);
app.use('/api', videoRouter);
// listen to port
app.listen(PORT, () => {
console.log(`Server started at port ${PORT} 🔥🚀`);
});