cyclopse87
cyclopse87

Reputation: 629

Using fs module in Meteor getting Uncaught TypeError _fs2.default.readFile is not a function

Hi i am trying to test the fs module in my Meteor project. I am using Meteor 1.3 new es2015 modules. I'm trying to use nodes fs module to read a file. tried a few methods but seem to be getting this same error when i run myFunc() in browser.

Uncaught TypeError: _fs2.default.readFile is not a function

import fs from 'fs'


myFunc = function(){

    fs.readFile('input.txt', function(err, data){
        if(err)
            console.log("Error" + err)

        console.log("Data from input" + data)
    })

}

Upvotes: 1

Views: 1797

Answers (1)

Kishor
Kishor

Reputation: 2677

I think you can't use fs module in the browser. There is a separate npm module for fs in the browser called fs-web. After installing this using npm install fs-web --save, you can use it by importing it in the client side files like this,

 import * as fs from 'fs-web';

Upvotes: 3

Related Questions