Last active
September 1, 2023 16:09
-
-
Save seeliang/5675ae8606e6c1db5adee24cbe0306a0 to your computer and use it in GitHub Desktop.
use node to generate html from ejs file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ejs = require('ejs'); | |
const fs = require('fs'); | |
module.exports = ({template, config}) => { | |
fs.readFile(template, 'utf8', (err, data) => { | |
if (err) { console.log(err); return false; } | |
var ejs_string = data, | |
template = ejs.compile(ejs_string), | |
html = template(config); | |
fs.writeFile(template.replace('.ejs', '') + '.html', html, (err) => { | |
if(err) { console.log(err); return false } | |
return true; | |
}); | |
}); | |
} | |
// const url = 'https://my.name.com'; | |
// ejs2html({template:__dirname+'/src/index.ejs', config:{url}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great! Thanks.
It's just what I was after. Made my day. :)
I'm trying to build an Express app that will serve "User preference" forms to a static site that stores the preferences locally in the browser. It's been driving me a bit crazy.
But a quick test suggests something like the following should work with an
app.get('/ejsForms/:file', (req, res) => {})
route:Anyway, thanks again. This really helps.
~ J