Answer the question
In order to leave comments, you need to log in
EJS (Node.js ) How to pass query string parameters to .ejs file?
Good day. I'm using the EJS template engine. On the main page (index.ejs) there is a link like this:
In app.js there is a code that should display the request parameters, but nothing is output to the console.
But if you change the path from href="/ create ?id=3&name=Tome" to href="/ about ?id=3&name=Tome" (although the about page doesn't exist)
and change it to app.js,
then everything works.
The console displays
How to pass query string parameters to the .ejs file?
Answer the question
In order to leave comments, you need to log in
Good day.
I'm not an expert in either node or express, but I'll try to chime in a bit about the lack of output of parameters to the console. Given that you are using the middleware without calling next(), and without sending a response back, then you must have completed processing requests on one of the first mw - this is most likely the reason that /create does not display something - or to the console. Without a normal link to the source, it's hard to say something.
BUT! because your question is in no way related to the situation you described, then you can pass query parameters to the template file as follows:
app.get('/create', (req, res) => {
res.render('name_of_ejs_file', req.query)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question