I have the URL: http://localhost:3000/homebrew/board?id=078262
I use node to get the id parameter and store it into a variable. When the page gets loaded, I use the variable with EJS to pass it to the client.
The issue is that if an id starts with zero 0, it gets removed.
App.JS
app.get('/homebrew/:homebrewType', (req, res) => {
var type = req.params.homebrewType;
var homebrewId = req.query.id;
console.log(homebrewId); // shows 078262
console.log(typeof homebrewId); // string
...
res.render('pages/homebrew-' + type, {
homebrewId: homebrewId
});
JS
var viewingHomebrew = <%= homebrewId %>;
console.log(viewingHomebrew); // shows 78262, starting 0 is missing
I don't have any other code, how can I preserve the id parameter?
You need to add quotes to make it a string instead of a number.
var viewingHomebrew = "<%= homebrewId %>";