-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.22 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
const express = require('express');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const morgan = require('morgan');
const helmet = require('helmet');
const userRoute = require('./routes/users');
const authRoute = require('./routes/auth');
const postRoute = require('./routes/posts');
const cors = require('cors')
const fs = require('fs');
const multer = require('multer');
const path = require('path');
const app = express();
app.use(cors());
app.use(helmet());
const port = process.env.PORT || 8000;
//------------Mongodb connection to database-------------
dotenv.config();
mongoose.connect(process.env.mongoURI,{ useNewUrlParser: true, useUnifiedTopology: true })
.then( () => {
console.log('Connected to database ✔️')
})
.catch( (err) => {
console.error(`Error connecting to the database. \n${err}❌`);
})
//-------------------middleware----------------------
app.use(express.json());
app.use(morgan("common"));
//-------------------API--------------------------
app.use("/api/user", userRoute);
app.use("/api/auth", authRoute);
app.use("/api/post", postRoute);
app.listen(port, () => {
console.log(`backend running on port:${port}🔥`);
})