Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access node.js File System module in Meteor

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?

like image 752
M Barrettara Avatar asked May 03 '12 19:05

M Barrettara


People also ask

How do you access a node JS module?

In order to use Node. js core or NPM modules, you first need to import it using require() function as shown below. var module = require('module_name'); As per above syntax, specify the module name in the require() function.

Does meteor use node JS?

Meteor is based on Node. js, thus all Meteor projects are written in JavaScript for both client and server side; that means you don't have to know any other language than JavaScript.

Which inbuilt module in node JS is used to access the file system?

js file system module helps us store, access, and manage data on our operating system. Commonly used features of the fs module include fs. readFile to read data from a file, fs. writeFile to write data to a file and replace the file if it already exists, fs.


1 Answers

From 0.6.0 you need to use Npm.require

var fs = Npm.require('fs');
like image 74
Tarang Avatar answered Sep 24 '22 23:09

Tarang