Meteor: reading simple JSON file
As per the docs, Assets.getText
is only available on the server as it's designed to read data in the private
directory, to which clients should not have access (thus the name).
If you want to deliver this information to the client, you have two options:
- Use
Assets.getText
exactly as you have done, but inside a method on the server, and call this method from the client to return the results. This seems like the best option to me as you're rationing access to your data via the method, rather than making it completely public. - Put it in the
public
folder instead and use something like jQuery.getJSON() to read it. This isn't something I've ever done, so I can't provide any further advice, but it looks pretty straightforward.
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"); Meteor.call('readit',function(err,response){ console.log(response); });}
Meteor!