I tried MongoDB Stitch earlier this year, and at the time it did not feel like a finished product (for example, apps cannot be renamed). I am giving it another go, and this time I am interested to see how I could create automated tests for my Stitch functions using Jest (this also may not be straightforward).
I have noticed that the Functions section has a DependenciesBeta tab. Here one may zip up NPM modules in a tarball, and they will become available in the Stitch JS environment. I wonder if I could use this to circumvent the import difficulties I am experiencing with the functions system - instead I could make (untested) lightweight calls from Functions to Dependencies, and then just test the dependencies.
However, I want to be able to import my app automatically using the console command, to deploy automatically in a CI pipeline. For this to work, import/export would need to include dependencies as well, but the file-format docs do not mention dependencies. Is there any support for syncing dependencies from the console, as part of an app import?
Is there any support for syncing dependencies from the console, as part of an app import?
Yes, you can import dependencies using mongodb-stitch-cli (v1.10+).
To upload external dependencies:
First need a local node_modules
folder containing at least one Node.js
package. If the node_modules
folder does not already exist, npm install <package>
will automatically creates it.
Next you need to package them up in an archive so you can upload them to Stitch:
tar -czf node_modules.tgz node_modules/
Other supported formats/extensions are : .zip
, .tar
, .gz
, .tgz
Next you can place the archive into the functions directory in the application file schema. i.e.
├── functions/
│ └── <function name>/
│ ├── config.json
│ └── source.js
│ └── node_modules.tgz
Execute the import command with --include-dependencies
, i.e:
stitch-cli import --app-id <APP_ID> --path ./your_app --include-dependencies
Creating draft for app...
Draft created successfully...
Importing app...
Deploying app...
Deploying app...
Done.
Importing hosting assets...
Done.
Please note that currently stitch-cli
does not support export for dependencies yet.
See also Stitch: Upload External Dependencies to upload from the UI.