-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (33 loc) · 1.17 KB
/
server.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
const express=require("express");
const app=express();
const dotenv = require('dotenv');
const helmet = require('helmet');
const mongoose = require('mongoose');
const cloudinary=require('cloudinary').v2;
const {assignId}=require('./middleware/assignId');
const {morganImpl}=require('./util/morgan');
const {router}=require('./route/route');
const {errorHandler}=require('./middleware/errorHandler');
const {processJWT}=require('./middleware/jwt');
// Adding environment
dotenv.config();
//connecting to database
mongoose.connect(process.env.MONGO_URL).then(()=>console.log("db connected")).catch((e)=>console.log(e));
// configuring cloudinary
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(assignId);
app.use(morganImpl);
app.use(helmet());
app.use('/multer/uploads',express.static('uploads'));
app.use(processJWT);
app.use('/api',router);
app.use(errorHandler);
app.listen(process.env.PORT || 4000,()=>{
console.log(`Server is listening on port ${process.env.PORT || 4000}`);
})