I'm creating a web app that will edit some config files stored on a user's HD, and decided to give Meteor a shot.
I'd like to use Node.js's File System module to handle to I/O of the config files, but I haven't been able to figure out how to include the module. After some searching, I found the following code here on StackOverlow, which is supposed to allow me to require the module:
var require = __meteor_bootstrap__.require;
var fs = require('fs');
However, even with this placed inside of the if(server) portion of my code, my application is still throwing an error and telling me that 'fs' is undefined.
Has anyone else encountered this issue?
I'm creating a web app that will edit some config files stored on a user's HD, and decided to give Meteor a shot.
I'd like to use Node.js's File System module to handle to I/O of the config files, but I haven't been able to figure out how to include the module. After some searching, I found the following code here on StackOverlow, which is supposed to allow me to require the module:
var require = __meteor_bootstrap__.require;
var fs = require('fs');
However, even with this placed inside of the if(server) portion of my code, my application is still throwing an error and telling me that 'fs' is undefined.
Has anyone else encountered this issue?
Share Improve this question edited May 3, 2012 at 19:17 maerics 156k47 gold badges277 silver badges299 bronze badges asked May 3, 2012 at 19:04 M BarrettaraM Barrettara 1031 silver badge4 bronze badges 5-
I put your exact code inside the
Meteor.startup
function and it worked. I was able to use the fs object to stat a file. Are you working from a fresh project, so you can be sure there isn't something else plicating things? – mwcz Commented May 4, 2012 at 1:27 - Thanks for giving the code a run. I tried the same code in a fresh project, but no luck. Maybe I'm just not referencing the require properly... if you wouldn't mind, could you share where and how you statted that file? – M Barrettara Commented May 4, 2012 at 1:56
- gist.github./2591352 Hope this helps. – mwcz Commented May 4, 2012 at 2:09
- @mwcz The code you linked to was a big help, thank you! It looks like this code worked all along - the real problem was in how I was trying to link the fs operations to the client side. – M Barrettara Commented May 4, 2012 at 10:33
-
The
__meteor_boostrap__.require
call is now deprecated in favor of Npm.require - please see Akshat's answer, which is now the best one. – Dan Dascalescu Commented May 6, 2013 at 11:27
1 Answer
Reset to default 18From 0.6.0 you need to use Npm.require
var fs = Npm.require('fs');