Reputation: 6499
I have several environment settings that I need to inject into my javascript assets. Thinks like database uri and facebook app id. I'm currently using EJS as my view engine.
Is there a simple way of templating javascript files in NodeJS?
Upvotes: 0
Views: 344
Reputation: 43243
Rather than trying to template your static files, I'd suggest using an initializer script instead.
Simply put a <script>
block in your layout, where you call a function in your JS file, which takes the DB uri and the FB app id as its parameters. The function can then store the values someplace where the rest of the scripts know how to access them.
You can easily pass your parameters into the layout (and views) for example by using helpers
Upvotes: 1