Guest User

Untitled

a guest
Dec 17th, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. const express = require('express');
  2. const cookieParser = require('cookie-parser');
  3. const bodyParser = require('body-parser');
  4.  
  5. const app = express();
  6.  
  7. // middlewares
  8. app.use(bodyParser.json());
  9. app.use(bodyParser.urlencoded({ extended: false }));
  10. app.use(cookieParser());
  11.  
  12. /*
  13. * GET /users route to retrieve all the users.
  14. * EXAMPLE
  15. */
  16. app.get('/users', (req, res) => {
  17. res.json([
  18. {
  19. id: 1,
  20. firstName: 'Bob',
  21. lastName: 'Smith',
  22. email: 'bob@gmail.com',
  23. },
  24. {
  25. id: 2,
  26. firstName: 'Tammy',
  27. lastName: 'Norton',
  28. email: 'tnorton@yahoo.com',
  29. },
  30. {
  31. id: 3,
  32. firstName: 'Tina',
  33. lastName: 'Lee',
  34. email: 'lee.tina@hotmail.com, ',
  35. },
  36. ]);
  37. });
  38.  
  39. /*
  40. * General 404
  41. */
  42. app.use((req, res) => {
  43. res.status(404).send({ url: `${req.originalUrl} not found` });
  44. });
  45.  
  46. module.exports = app;
Add Comment
Please, Sign In to add comment