Christian Fritz
Christian Fritz

Reputation: 21374

What's the best way to find all assets in a meteor application?

I know it is possible to just read the program.json file, which lists all assets: https://github.com/meteor/meteor/issues/1328#issuecomment-22913769

But this sort of feels wrong, and I couldn't find out whether this will be supported going forward. The documentation on assets itself is still a little sparse in this regard (http://docs.meteor.com/#assets).

Is there a best practice on how to list all assets?

Upvotes: 5

Views: 390

Answers (1)

outofambit
outofambit

Reputation: 43

I don't know if this is a best practice, but I got most of the way there by using meteor package https://github.com/peerlibrary/meteor-fs (which is a thin wrapper around https://nodejs.org/api/fs.html) and doing some poking around. Turns out the assets are put into a folder called app/.

Here's what my code looked like:

if (Meteor.isServer) {
    Meteor.startup(function() {
        // clear database and load everything in the articles folder
        fs.readdir("assets/app/", function(err, files) {
            if (err) throw err;
            files.forEach(function (val, ind, arr) {
                console.log(val);
            });
        });
    });
}

Upvotes: 3

Related Questions