forked from jonnygovish/gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (37 loc) · 1.19 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const path = require('path');
const config = require('./_config');
// Define routes
let index = require('./routes/index');
let image = require('./routes/image');
// Initializing the app
const app = express();
// connecting the database
const MONGODB_URI = process.env.MONGODB_URI || config.mongoURI[app.settings.env]
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true },(err)=>{
if (err) {
console.log(err)
}else{
console.log(`Connected to Database: ${MONGODB_URI}`)
}
});
// test if the database has connected successfully
// let db = mongoose.connection;
// db.once('open', ()=>{
// console.log('Database connected successfully')
// })
// View Engine
app.set('view engine', 'ejs');
// Set up the public folder;
app.use(express.static(path.join(__dirname, 'public')));
// body parser middleware
app.use(express.json())
app.use('/', index);
app.use('/image', image);
const PORT = process.env.PORT || 5000;
app.listen(PORT,() =>{
console.log(`Server is listening at http://localhost:${PORT}`)
});
module.exports = app;