-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
43 lines (33 loc) · 1.05 KB
/
app.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
const express = require('express')
const bodyParser=require('body-parser')
const dotenv = require('dotenv')
const morgan = require('morgan')
/* initializing packages */
//requiring routes
const algoRoutes = require('./routes/algo')
const basicRoutes = require('./routes/basic')
//initializing app
const app = express()
//body-parser configuration
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}))
//setting view engine
app.set('view engine', 'ejs')
//setting public directory
app.use(express.static(__dirname + '/public'))
//requiring env variables in process.env
dotenv.config({ path: './config/config.env' })
//declaring variables
const PORT = process.env.PORT || 6000
const NODE_ENV = process.env.NODE_ENV
//setting morgan dev if we are in development mode
if(NODE_ENV === 'development'){
app.use(morgan('dev'))
}
//routing all request
app.use('/', basicRoutes)
app.use('/algorithms', algoRoutes)
app.listen(
PORT,
() => { console.log(`Server started at ${PORT} in ${NODE_ENV} mode.`) } // use tilde ` to parse ${variable}
)