Created
August 31, 2016 14:36
-
-
Save themeteorchef/b8547c49762c063083644219e27b3674 to your computer and use it in GitHub Desktop.
Native Node.js File Read in Meteor
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
/* | |
Read a file with Node's fs instead of Meteor's Assets lib. | |
Originally used as a swap for Meteor's Assets.getText() method not working consistently. | |
*/ | |
import fs from 'fs'; | |
const file = 'some-file-in-private.html'; | |
// assets/app here is analagous to your /private directory in the root of your app. This is where Meteor ultimately | |
// stores the contents of /private in a built app. | |
const text = fs.readFileSync(`assets/app/${file}`, 'utf8'); | |
console.log(text); // File contents as utf8 encoded string. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment