I am confused, i need to use fs package for meteor.js fw.
From meteor version 0.6> i need to use Npm.require like this:
var fs = Npm.require('fs');
But when i do it an error appear: npm is not defined
How to solve it? I tried mrt add npm but hm...
BTW: i have /root/packages/npm
EDIT My code was in the both client/server side folder so i moved it to the block for a server as
var fs;
if(Meteor.isServer) {
fs = Meteor.require('fs');
}
fs.writeFile(path + name,...
GETTING ERROR: Cannot call a method writeFile of undefined
SOLVED Well i solved the error by wraping the whole content to the Meteor.isServer {... but if someoen could explain to me from curiosity why it does not work like above?
It's Npm
, not npm
, and in your question you use both. Javascript is case-sensitive, make sure you use the proper Npm
form.
You need to add a package.js
in your app or a smart package that explicitly specifies the dependency via Npm.depends
before you can use Npm.require
. You don't need the Npm.depends
or a smart package if you are using a built-in npm
package such as fs
, but you still need to make sure you are using it on the server-side and not the client side.
For an example, check out the package.js
file for my Meteor package that pulls in ShareJS:
https://github.com/mizzao/meteor-sharejs/blob/master/sharejs-ace/package.js
See also this post: http://shiggyenterprises.wordpress.com/2013/05/16/accessing-the-file-system-in-meteor/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With