-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (32 loc) · 887 Bytes
/
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
/*
Library Initialisations
*/
const mongoose = require('mongoose')
require('dotenv').config()
const morgan = require('morgan')
const express = require('express')
const userRoutes = require('./src/routes/userRoutes')
/*
Constants & Env Variables
*/
const PORT = process.env.PORT || 3000
const DATABASE_URL = process.env.DATABASE
const DATABASE_PASSWORD = process.env.DATABASE_PASSWORD
const NODE_ENV = process.env.NODE_ENV
//Database initialization
const finalUrl = DATABASE_URL.replace('<PASSWORD>', DATABASE_PASSWORD)
console.log(finalUrl)
mongoose.connect(finalUrl, {}).then(con => {
console.log('Connections successful!')
})
//App initialization
const app = express()
if (NODE_ENV == 'development') {
app.use(morgan('dev'))
}
//Routers
app.use('/users', userRoutes)
//Port initialization
app.listen(PORT, () => {
console.log(`Server is running on PORT ${PORT}`)
})