-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
42 lines (30 loc) · 1.24 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
// import express
//ok
const express = require('express')
// app is the express server
const app = express()
const path = require('path')
const mongoose = require('mongoose')
const port = process.env.PORT || 8000;
//require('dotenv').config()
app.use(express.json())
// serve public files to client
app.use(express.static(path.join(__dirname, '/public')));
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
mongoose.Promise = global.Promise;
const databaseUri = "mongodb://dbUser:[email protected]:27017,cluster0-shard-00-01-of6ji.mongodb.net:27017,cluster0-shard-00-02-of6ji.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority";
mongoose.connect(databaseUri, {
useNewUrlParser: true,
useCreateIndexL: true
})
.then(() => console.log(`Database connected`))
.catch(err => console.log(`Database connection error: ${err.message}`));
const bugsRouter = require('./routes/bugs')
const usersRouter = require('./routes/users')
app.use('/bugs', bugsRouter)
app.use('/users', usersRouter)
// starts a UNIX socketand listens for connections on the given path
app.listen(port, () => {
console.log('Example app listening on port 8000!')
});