While working on the impossible-hangman game I stumbled over the problem of accessing the hosts filesystem from Meteor. I intended in earlier versions of the game, to load the dictionary from a file. Meteor sits on top of Node.js, so I wondered if simply using the fs-module, like I would do in plain Node, might solve the problem. Unfortunately, you cannot use require in your app code. There has to be a way to include the module and there was a solution that worked until version 0.6.0 of Meteor:
fs = __meteor_bootstrap__.require 'fs'
But the more recent versions of Meteor don’t seem to support this way any longer. Instead they embrace Node’s modules system: npm, but only in packages. So you can not do:
in your app code. You have to create an app-private package. This is actually very simple. Create a subfolder called packages and in it, create another folder fs. In the latter folder you have to put a package.js file and a file providing the sources for the packages. The following gist shows the package definition. There is a little overhead, though, because I’m using CoffeeScript for the package’s source code. Absolutely unnecessary, actually:
The next gist shows the code of fs.coffee.
Now I can access fs and path in my apps standard code files. Keep in mind though, that this won’t work if you plan to deploy your app to your_app.meteor.com. I guess some security restrictions are in place there. Here is an example of using both modules an app code: