最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Access node.js File System module in Meteor - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 18

From 0.6.0 you need to use Npm.require

var fs = Npm.require('fs');
发布评论

评论列表(0)

  1. 暂无评论