Advertisement
Shell_Casing

server.js

May 10th, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const path = require('path');
  4. const cors = require('cors');
  5.  
  6. const port = process.env.port || 3000;
  7.  
  8. const { database } = require('./database');
  9.  
  10. const router = require('./router');
  11.  
  12. const app = express();
  13.  
  14. app.use(cors());
  15.  
  16. // static folder
  17. app.use(express.static(path.join(__dirname, 'dist')));
  18.  
  19. // parse requests of content-type - application/x-www-form-urlencoded
  20. app.use(bodyParser.urlencoded({ extended: false }));
  21.  
  22. // parse requests of content-type - application/json
  23. app.use(bodyParser.json());
  24.  
  25. // route to retrieve all employees from the database
  26. app.use('/employees', router);
  27.  
  28. // route to save an employee to the database
  29. app.use('/employees/register', router);
  30.  
  31. // route to update an employee's details
  32. app.use('/employees/update/id', router);
  33.  
  34. // route to delete an employee
  35. app.use('/employees/delete/employee/id', router);
  36.  
  37. // handle all other requests
  38. app.get('*', (req, res) => {
  39.   res.sendFile(path.join(__dirname, 'dist/index.html'));
  40. });
  41.  
  42. app.listen(port, () => console.log('Server running on port ' + port));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement