How to console.log in pug? How to console.log in pug? express express

How to console.log in pug?


Your current method of accessing the data within the template will log information on the backend in the terminal where Express is running, not the frontend in Chrome Developer Tools.

In order to access the external information inside the template, you need to nest it inside a script tag and use JSON.stringify in combination with unescaped Pug string interpolation to render it in the HTML as below.

script     | var species = !{JSON.stringify(stream.species)};     | var fields = [];     | for (var key in species) fields.push(key)     | console.log(fields)