Skip to content Skip to sidebar Skip to footer

Reading Environment Variables From Pug

I'm using pug to compile static html. My own static site generator, kinda. I have no node.js server code besides this line in my package.json file: 'watch-pages': 'pug -O options.j

Solution 1:

This is fairly simple; you may find another way to do it but what I tried (successfully) was to simply define a .js file to pass as the options parameter which includes the variables I wanted. For example:

// env.js
module.exports = { env: process.env };

Then the template can be something like:

// tmp.pug
ul
  each e in env
    li=e

And you can then run pug -O env.js tmp.html and it will create a env.html with the environment variables rendered as list items.


Post a Comment for "Reading Environment Variables From Pug"