[Fixed] How to id print the value of the variable in res.json(message: {})

Issue

I want to print the value of orderId in the message section of res.json() but I am getting the exact string after the $ symbol

 if(order.length > 0)
        {
          res.status(200).json(order);
        }
        else{
          res.json({message: 'No orders Found with orderId ${orderId}'});
        }
      }).catch(err => console.log(err));

Solution

 if(order.length > 0)
        {
          res.status(200).json(order);
        }
        else{
          res.json({message: `No orders Found with orderId ${orderId}`});
        }
      }).catch(err => console.log(err));

use ` (back-ticks) instead of ‘ (single quotes).
ES6 Template Strings

Leave a Reply

(*) Required, Your email will not be published