Assets

Documentation of how to use assets in Meteor.

Currently, it is not possible to import Assets as an ES6 module. Any of the Assets methods below can simply be called directly in any Meteor server code.

Assets allows server code in a Meteor application to access static serverassets, which are located in the private subdirectory of an application’stree. Assets are not processed as source files and are copied directlyinto your application’s bundle.

Server

Assets.getText(assetPath, [asyncCallback])

Retrieve the contents of the static server asset as a UTF8-encoded string.

Arguments

  • assetPathString
  • The path of the asset, relative to the application's private subdirectory.

  • asyncCallbackFunction

  • Optional callback, which is called asynchronously with the error or result after the function is complete. If not provided, the function runs synchronously.

Server

Assets.getBinary(assetPath, [asyncCallback])

Retrieve the contents of the static server asset as an EJSON Binary.

Arguments

  • assetPathString
  • The path of the asset, relative to the application's private subdirectory.

  • asyncCallbackFunction

  • Optional callback, which is called asynchronously with the error or result after the function is complete. If not provided, the function runs synchronously.

Server [Not in build plugins]

Assets.absoluteFilePath(assetPath)

Get the absolute path to the static server asset. Note that assets are read-only.

Arguments

  • assetPathString
  • The path of the asset, relative to the application's private subdirectory.

Static server assets are included by placing them in the application’s privatesubdirectory. For example, if an application’s private subdirectory includes adirectory called nested with a file called data.txt inside it, then servercode can read data.txt by running:

  1. const data = Assets.getText('nested/data.txt');

Note: Packages can only access their own assets. If you need to read the assets of a different package, or of the enclosing app, you need to get a reference to that package’s Assets object.