Question

I am trying to user Faker.js with Meteorite. I have added this package:

https://atmosphere.meteor.com/package/Faker.js

I am trying to add fake users on server startup:

Meteor.startup(function () {
    // code to run on server at startup

    // add 100 fake tips and 10 fake articles and 50 fake users
    for (var i=0; i<50; i++) {
        // Accounts.createUser(Faker.Internet.userName(), Faker.Internet.email(), "1234");
    }

});

but I get an error:

ReferenceError: Faker is not defined

Not sure how to fix this...

Was it helpful?

Solution

I'd recommend installing the npm package, and adding Faker as an NPM module. It's quite simple:

  1. mrt add npm
  2. Create a packages.json file in your project root, and add { "Faker": "0.5.11" }
  3. mrt update
  4. Use Faker in your code by doing Faker = Meteor.require('Faker');

Now you can use it like normal, e.g. Faker.Internet.email()

OTHER TIPS

The author of Faker.js on atmosphere needs to update the package for it to work properly on Meteor 0.6.5.

In meteor 0.6.5 packages need to explicitly expose their variables. This was done so that packages variables don't conflict.

For the 'fakerjs' package the edits look pretty minor because it just interfaces the npm module.

You need to export 'Faker' in the package.on_use method in the package.js with an api.export, if you contact the author or send him a push request you could push it through faster. More details on how to expose the variables can be found in the namespacing section on the meteor docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top