Speed up development with full-stack environments for every branch.

Learn More

kkk [express and Node.js]

Forked from Hello World in Express.

5 Runs 11 Views 1 Copies
Saved

Saved

ooiloo 1

ooiloo
published 7 days ago

    var express = require('express');
    var app = express({mergeParams: true});
    
    app.get('/:place/:id([0-9]{1,})', function(req, res){
      var products = [
        {
            place1:[
                {id: 1, name: "choc1", price: 20},
                {id: 2, name: "choc2", price: 30}
            ],
            place2:[
                {id: 1, name: "coffee", price: 50}
            ],
            place3: [
                {id: 1, name: "oil1", price: 10},
                {id: 2, name: "oil2", price: 60},
                {id: 3, name: "oil3", price: 70}
            ]
        }
    ];
    
      if (products[0][req.params.place] === undefined)
      res.send("place doesnt exist");
    else {
        if (products[0][req.params.place][req.params.id - 1] === undefined)
            res.send ("id doesnt exist");
        else {
            res.send ("it exists....!!!!");
        }
    }
    });
    
    app.listen(80);
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).