Search code examples
meteortypescriptangularangular2-meteor

Meteor with Angular 2 - how to use node libraries like fs and others?


all !

Basic question : In many previous app, I'm used to do in this way:

const fs = require('fs');

this does not work as well...

var fs = Npm.require('fs');

Now...using angular 2 with meteor and typescript I've no clue how to produce the same line of code.

Any solution ? Actually I just need to load a json file from my File System, but in the future I will need to use many others libs like S3 (amazon) and others.

ty !


Solution

  • I'm assuming you are using Meteor version 1.3? If so, please take a look at this section of the Meteor guide. Meteor 1.3 uses ES2015 module syntax with the import and export keywords. You can learn more about this syntax here.

    In your case, you should be able to import and use the fs npm package in your Meteor apps as so:

    import fs from 'fs'
    

    Then that variable is available for you to use through that file.

    Of course, this is assuming you've first installed and saved the npm package to your project via meteor npm install <package-name> --save

    I am not sure if you have used it before but this Angular2-Meteor tutorial should come handy as well.