Jaspermid Jaspermid - 19 days ago 6x
JSON Question

Meteor: reading simple JSON file

I am trying to read a JSON file with Meteor. I've seen various answers on stackoverflow but cannot seem to get them to work. I have tried this one which basically says:

  1. Create a file called private/test.json with the following contents:


  1. Read the file contents when the server starts (server/start.js):

Meteor.startup(function() {

However this seemingly very simple example does not log anything to the console. If I trye to store it in a variable instead on console.logging it and then displaying it client side I get

Uncaught ReferenceError: myjson is not defined

where myjson was the variable I stored it in. I have tried reading the JSON client side

'click input': function () {
myjson = JSON.parse(Assets.getText("myfile.json"));

Which results in:

Uncaught ReferenceError: Assets is not defined

  1. If have tried all of the options described here: Importing a JSON file in Meteor with more or less the same outcome.

Hope someone can help me out


The server method is OK, just remove the extra semi-colon(;). You need a little more in the client call. The JSON data comes from the callback.

Use this in your click event:

if (typeof console !== 'undefined'){
    console.log("You're calling readit");