ejs

Pass variables to JavaScript in ExpressJS

China☆狼群 提交于 2019-11-26 03:54:59
问题 I am completely lost on this; I am using NodeJS to fetch a JSON and I need to pass the variable to my page and have JavaScript use the data. app.get(\'/test\', function(req, res) { res.render(\'testPage\', { myVar: \'My Data\' }); That is my Express code (very simple for testing purposes); now using EJS I want to gather this data which I know to render on the page is simply <%= myVar %> But I need to be able to gather this data in JavaScript (if possible within a .js file) but for now just to