- Meteor - Best Practices
- Meteor - ToDo App
- Meteor - Running on mobile
- Meteor - Deployment
- Meteor - Structure
- Meteor - Publish & Subscribe
- Meteor - Package.js
- Meteor - Methods
- Meteor - Accounts
- Meteor - Sorting
- Meteor - Security
- Meteor - Assets
- Meteor - Email
- Meteor - HTTP
- Meteor - EJSON
- Meteor - Timers
- Meteor - Blaze
- Meteor - Check
- Meteor - Core API
- Meteor - Packages
- Meteor - Tracker
- Meteor - Session
- Meteor - Events
- Meteor - Forms
- Meteor - Collections
- Meteor - Templates
- Meteor - First Application
- Meteor - Environment Setup
- Meteor - Overview
- Meteor - Home
Meteor Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Meteor - Assets
Static server assets are located in a private subfolder inside the app. In the following example, we will learn how to use data from a simple JSON file.
Step 1 - Create Files and Folders
Let s create a private folder and my-json.json file inside that folder. We will do this using the following command in the command prompt window, however, you can also create it manually.
C:UsersusernameDesktopmeteorApp>mkdir private C:UsersusernameDesktopmeteorAppprivate>touch my-json.json
Step 2 - Get Text
To be able to read data from our file, we will use Asssets.getText method. Note, this can only be done from the server side. Since we are using JSON, we need to parse it.
if (Meteor.isServer) { var myFile = JSON.parse(Assets.getText( my-json.json )); console.log(myFile.data.text) }
Following will be the output in the command prompt window.
![Meteor Assets Get Text](/meteor/images/meteor-assets-get-text.jpg)
Step 3 - Create EJSON File
We will create this file inside the private folder. This file will contain binary data "myBinary": {"$binary": "c3VyZS4="}
C:UsersusernameDesktopmeteorAppprivate>touch my-ejson.ejson
Step 4 - Get Binary
To read EJSON files, we can use the Assets.getBinary method.
if (Meteor.isServer) { var myFile = Assets.getBinary( my-ejson.ejson ); console.log(EJSON.stringify(myFile)); }
The command prompt will log EJSON value.
![Meteor Assets Get Binary](/meteor/images/meteor-assets-get-binary.jpg)