Reputation: 693
i have an application in nodejs. now i am sending a parameter along with the url which i want to use in the script part of html. below is my code present in route :
app.use('/overview',function(req, res) {
module.exports.dbname = req.query.dbname;
res.sendFile(path.join(__dirname, '../public/html', 'overview.html'));
});
Below is the code present in my overview.html file:
<script>
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
filter = {
"start" : start.format('YYYY-MM-DD'),
"end" : end.format('YYYY-MM-DD '),
"gender" : gender,
"dbname" : //dbname from url will come here
});
};
</script>
now i want to use the dbname in my overview.html part to send it as a parameter for backend calls. I can load it directly in my js file but that will not serve my purpose. How can it be done.
Upvotes: 0
Views: 78
Reputation: 952
You are using res.sendFile, so you cannot pass any data with it because that just reads a file from disk and streams it as the response, giving you no chance to modify it
You need template systems to accomplish your task (EJS,Handlebars,Mustache)
Upvotes: 0
Reputation: 1915
I think the best approach would be to take a look at a template engine such as handlebars or pug
Upvotes: 1