Navigation

Upload External Dependencies

On this page

  • Overview
  • Procedure
  • Locally Install External Dependencies
  • Create a Dependency Archive
  • Upload the Dependency Archive
  • Summary
  • Next Steps

You can upload JavaScript modules from the npm registry into your Realm app and use the uploaded external dependencies in your Functions. This allows your application to depend upon external libraries and reuse code.

To use external dependencies, you must first upload an archive of an npm node_modules folder. MongoDB Realm automatically transpiles uploaded modules to ES5 and supports most built-in modules. You can import an uploaded module in any Realm Function.

You can see a list of uploaded packages on the Functions screen of the Realm UI under the Dependencies tab.

Important
External Dependency Size Constraints

Uploaded node_modules archive files are subject to a 10MB size cap.

1

To upload external dependencies, you first need a local node_modules folder containing at least one Node.js package. You can use the following code snippet to install a dependency locally you would like to upload:

npm install <package name>

If the node_modules folder does not already exist, this command automatically creates it.

Note
Alternative Methods of Installation

You can also configure a package.json and run the npm install command to install all packages (and their dependencies) listed in your package.json.

To learn more about npm and node_modules, consult the npm documentation .

2

Now that you've downloaded all of your npm modules, you need to package them up in an archive so you can upload them to Realm. Create an archive containing the node_modules folder:

tar -czf node_modules.tar.gz node_modules/
Note
Supported Archive Formats

Realm supports .tar, .tar.gz, and .zip archive formats.

3

Once you've created an archive containing your dependencies, you can upload your dependency archive using the Realm UI or realm-cli:

  • External Dependencies can be uploaded through the Realm UI
  • Uploaded Dependencies can be used in Realm Functions
  • You have installed and archived your external dependencies locally, uploaded them to MongoDB Realm, and deployed your application. Now you can import external dependencies in a Realm Function.
Give Feedback

On this page

  • Overview
  • Procedure
  • Locally Install External Dependencies
  • Create a Dependency Archive
  • Upload the Dependency Archive
  • Summary
  • Next Steps