sanjay555

index.js

Feb 8th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const PORT = 5000;
  3.  
  4.  
  5. const app = express();
  6.  
  7. // http://localhost:5000/table/100?id=1
  8. // http://localhost:5000/table/100?id=11
  9. app.use('/table/:amount/', (req, res, next) => {
  10.   let user_id = req.param('id');  
  11.   console.log(`User ID: ${user_id}`);
  12.  
  13.  
  14.   if (user_id > 10) {
  15.     console.log(`Passed User Id: ${user_id}`);
  16.     next();
  17.   }else {
  18.     console.log(`pass correct id`);
  19.    
  20.   }
  21. })
  22. // http://localhost:5000/table/100?id=123
  23. app.get('/table/:amount/', (req, res) => {
  24.   var user_id = req.param('id');
  25.   // var user_id = req.params.id;
  26.   // var user_id = 121;
  27.   var amount = req.params.amount;
  28.   console.log(`Amount: ${amount} Id: ${user_id}`);  
  29.   res.send(`ID: ${user_id} Amount: ${amount}`)
  30. });
  31.  
  32. // user?id=12345
  33. app.get('/user', (req, res) => {
  34.   var idd = req.param('id');
  35.   res.send(`UIDD: ${idd}`)
  36. })
  37.  
  38. app.listen(PORT, () => {
  39.   console.log(`We're live on PORT: ${PORT}`);  
  40. })
Add Comment
Please, Sign In to add comment