-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (29 loc) · 1.09 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
44
45
46
47
48
49
50
// Task1: initiate app and run server at 3000
const express = require('express');
const app = express();
const morgan = require('morgan');
app.use(morgan('dev'));
require('dotenv').config();
const PORT = process.env.PORT;
app.use(express.json());
app.use(express.urlencoded({extended:true}));
const path = require('path');
app.use(express.static(path.join(__dirname+'/dist/FrontEnd')));
// Task2: create mongoDB connection
require('./DB connection');
//Task 2 : write api with error handling and appropriate api mentioned in the TODO below
const employeeGet = require('./routes/get');
const employeePut = require('./routes/put');
const employeePost = require('./routes/post');
const employeeDelete = require('./routes/delete');
app.use('/api',employeeGet);
app.use('/api',employeePut);
app.use('/api',employeePost);
app.use('/api',employeeDelete);
//! don't delete this code. it connects the front end file.
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname + '/dist/Frontend/index.html'));
});
app.listen(PORT,()=>{
console.log(`Server is listening on port ${PORT}`);
});