Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const PORT = 5000;
- const app = express();
- // http://localhost:5000/table/100?id=1
- // http://localhost:5000/table/100?id=11
- app.use('/table/:amount/', (req, res, next) => {
- let user_id = req.param('id');
- console.log(`User ID: ${user_id}`);
- if (user_id > 10) {
- console.log(`Passed User Id: ${user_id}`);
- next();
- }else {
- console.log(`pass correct id`);
- }
- })
- // http://localhost:5000/table/100?id=123
- app.get('/table/:amount/', (req, res) => {
- var user_id = req.param('id');
- // var user_id = req.params.id;
- // var user_id = 121;
- var amount = req.params.amount;
- console.log(`Amount: ${amount} Id: ${user_id}`);
- res.send(`ID: ${user_id} Amount: ${amount}`)
- });
- // user?id=12345
- app.get('/user', (req, res) => {
- var idd = req.param('id');
- res.send(`UIDD: ${idd}`)
- })
- app.listen(PORT, () => {
- console.log(`We're live on PORT: ${PORT}`);
- })
Add Comment
Please, Sign In to add comment