-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
39 lines (30 loc) · 1.01 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
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const multer = require('multer');
const crypto = require('crypto');
require('dotenv').config()
const app = express();
// Routes
const indexroute = require('./routes/index')
const contributor_route = require('./routes/contributors')
const material_route = require('./routes/material')
app.set('view engines', 'ejs');
app.use(express.urlencoded({extended: true}));
app.use(express.static(__dirname + '/public'));
app.use(express.json());
let name = process.env.DB_NAME;
let pass = process.env.DB_PASS;
// Connecting to MongoDB
const dbURI = `mongodb+srv://Tijan:${pass}@getting-started-with-no.sdrkl.mongodb.net/${name}?retryWrites=true&w=majority`
mongoose.connect(dbURI)
.then((result)=>{
app.listen(process.env.PORT || 3000);
})
.catch((err)=>{
console.log(err);
});
// Using Routes
app.use(indexroute);
app.use('/contributors', contributor_route);
app.use('/materials', material_route);