How can I use url query string when working with ejs


Is there a way to pass a query string inside a href in ejs? I want to be able to click on a link and use the the link parameter inside my db query. Here’s the code I’m playing with at the moment

//ejs view
<% if (data) { %>
<% data.forEach(function(car) { %>
    <div class="card mb-3">
        <a href="/cars/:id">
            <div class="card-body text-center text-capitalize">
                <div class="card-title"><%= car.brand %></div>
                <p class="card-text text-muted"><%= car.color %> / <%= car.engine_type %></p>
<% }) %>
<% } %>

In my routes file, I want to query like this

router.get('/cars/:id?', function(req, res) {
var carId =;

res.locals.connection.query('SELECT * FROM cars WHERE id = ?', [carId], function(err, row) {
    if(err) {
    } else {

Right now i get a 304 status when i run my app because i’m not passing back the id. How can i pass it back? I have no idea and haven’t been successful with my search.