Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3.  
  4. const app = express();
  5. app.use(bodyParser.json());
  6.  
  7. const database = {
  8. users: [
  9. {
  10. id: 1,
  11. name: 'John',
  12. email: 'john@gmail.com',
  13. password: 'password123',
  14. entries: 0,
  15. joined: new Date()
  16. },
  17. {
  18. id: 2,
  19. name: 'Sally',
  20. email: 'sally@gmail.com',
  21. password: 'password321',
  22. entries: 0,
  23. joined: new Date()
  24. }
  25. ]
  26. }
  27.  
  28. app.get('/', (req, res) => {
  29. res.send('this is working');
  30. })
  31.  
  32. app.post('/signin', (req, res) => {
  33. if(req.body.email === database.users[0].email &&
  34. req.body.password === database.users[0].password) {
  35. res.json('success');
  36. } else {
  37. res.status(400).json('error');
  38. }
  39. })
  40.  
  41. app.listen(3001, () => {
  42. console.log("App is running on port 3001!");
  43. })
  44.  
  45. /*
  46.  
  47. / --> res = this is working
  48. /signin --> POST = success/fail
  49. /register --> POST = new user
  50. /profile/:userID --> GET = user profile
  51. /image --> PUT = updated user object
  52.  
  53. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement