Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Created August 31, 2016 14:36
Show Gist options
  • Save themeteorchef/b8547c49762c063083644219e27b3674 to your computer and use it in GitHub Desktop.
Save themeteorchef/b8547c49762c063083644219e27b3674 to your computer and use it in GitHub Desktop.
Native Node.js File Read in Meteor
/*
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