-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 956 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 956 Bytes
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
// dotenv for process environment variables
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// connect to database simple-rest-api
mongoose.connect(process.env.MONGODB_URI)
.then(() => console.log('Connected to Database!'))
.catch((error) => console.log(error));
// setup express middleware
const app = express();
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.json());
// use separate route handler for customers
const customerRouter = require('./routes/customerRouter');
app.use('/api/customer', customerRouter);
// base endpoint for validation
app.get('/api', ( req, res) => {
res.json({
'API Name': 'Simple-Rest-API',
'Author':'S.Jeyavishnu',
'Status':'Active'
})
});
// bootstrapping server
app.listen( process.env.PORT || 3000, () => console.log('Server Started at port 3000.'));