0

I'm using Meteor 1.13 (Latest version) and they've added NPM support recently. So I added in the Lob.com NPM. I began to make a letter function and I get this error:

Uncaught TypeError: fs.readdirSync is not a function

This is what my function looks like:

import { Meteor } from 'meteor/meteor';
import 'lob';

Meteor.methods({

sendLetter(name) {

    Lob.letters.create({
    description: 'Garrison Snelling',
    to: {
        name: name,
        address_line1: '123 Test Street',
        address_city: 'Mountain View',
        address_state: 'CA',
        address_zip: '94041',
        address_country: 'US',
    },
    from: {
        name: 'Ami Wang',
        address_line1: '123 Test Avenue',
        address_city: 'Mountain View',
        address_state: 'CA',
        address_zip: '94041',
        address_country: 'US',
    },
    file: '<html style="padding-top: 3in; margin: .5in;">HTML Letter for {{name}}</html>',
    data: {
        name: 'Harry'
    },
    color: true
    }, function (err, res) {
    console.log(err, res);
    })
    .then(function (res) {
        console.log('The Lob API responded with this letter object: ', res);
    });

}


});

I've tried including 'fs' manually, but no luck... I've tried:

var fs = require('fs'); // Didn't fail, but got same error
const fs = require('fs'); // Didn't fail, but got same error 
var fs = Npm.require('fs'); // Didn't fail, but got same error
var fs = npm.require('fs'); // Failed
var fs = Meteor.require('fs');

None of these worked! Any help on what is going on here would help.. Thanks!

1 Answers1

0

So as most of you may know.. fs is only available in node not say the frontend.

So I hadn't included my Meteor.Method in the server so it was having file permission issues. Once I moved it inside the server folder it was good to go!