Docs Menu

Add External Dependenciesicons/link.png

On this page

  • Specify npm Packages
  • Upload Zipped node_modules (Legacy)
  • Summary
  • Next Steps

You can add JavaScript modules from the npm registry into your Realm app and use the added external dependencies in your Realm Functions. This lets your application depend on external libraries and reuse code.

MongoDB Realm automatically transpiles added 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.

There are currently two ways to add dependencies to your Realm app:

You can specify npm packages to use in your Realm Functions and the MongoDB Realm imports them. You can do this with the Realm UI, Realm CLI, and Github Automatic Deployments.

You must first upload an archive of an npm node_modules folder. Uploaded node_modules archive files are subject to a 10MB size cap.

Important
Overriding Existing Dependencies

Uploading zipped node_modules overrides all existing dependencies. Your Realm Functions only have access to uploaded dependencies.

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, .tgz, 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:

  • Dependencies can be used in Realm Functions
  • You can use external dependencies by:

    • Pushing a package.json including dependencies with the Realm CLI.
    • Selecting packages to be installed with the Realm UI.
    • Pushing a zip file of dependencies with the Realm CLI.
    • Uploading a zip file of dependencies with the Realm UI.
Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.