Upload External Dependencies¶
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.
node_modules archive files are subject to a
10MB size cap.
Locally Install External Dependencies¶
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>
node_modules folder does not already exist, this command
automatically creates it.
You can also configure a
package.json and run the
npm install command to install all packages (and their
dependencies) listed in your
To learn more about npm and
node_modules, consult the
npm documentation .
Create a Dependency Archive¶
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
tar -czf node_modules.tar.gz node_modules/
Upload the Dependency Archive¶
Once you've created an archive containing your dependencies, you can upload your
dependency archive using the Realm UI or
- Select Functions from the left navigation menu.
- Select the Dependencies tab.
- Click the Upload button.
- In the file picker, select the
node_modules.tar.gzarchive you just created and click Open. Realm automatically uploads the archive file, which may take several minutes depending on the speed of your internet connection and the size of your dependency archive.
- Whether the operation succeeded or failed, Realm displays a banner indicating the success or failure of the operation. If successful, the Dependencies tab displays a list of the dependencies that you included in your dependency archive. If drafts are enabled, you will also need to click Review & Deploy to apply these changes. If drafts are disabled, the change will take effect within 5 to 60 seconds depending on the size of your dependency archive.
- 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.