Pass variables to JavaScript in ExpressJS
You could use this (client-side): <script> var myVar = <%- JSON.stringify(myVar) %>; </script> You could also get EJS to render a .js file: app.get(‘/test.js’, function(req, res) { res.set(‘Content-Type’, ‘application/javascript’); res.render(‘testPage’, { myVar : … }); }); However, the template file (testPage) would still need to have the .html extension, otherwise EJS won’t find it (unless … Read more