-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (24 loc) · 853 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
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const db = require('./db')
const employeeRouter = require('./routes/employees')
const EmployeeCtrl = require('./controllers/employee')
const app = express()
const apiPort = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())
app.use(bodyParser.json())
db.on('error', console.error.bind(console, 'MongoDB connection error:'))
db.once('open', function(){
// we are connected to Database
console.log('Connected to MongoDB');
})
app.use('/employees', employeeRouter)
app.use('/', (req, res) => {
return res.status(200).json({
'success' : true,
data : 'This is home page for employee app'
})
})
app.listen(apiPort, () => console.log(`Server running on port ${apiPort}`))