Bundled Node modules
You can use the node_modules
folder to bundle Node.js modules with your Foxxservice. Note that many third-party libraries written for Node.js or thebrowser rely on async or filesystem logicwhich may not be compatible with Foxx.
Bundled node modules are often referred to as dependencies. In ArangoDB thisterm can often be ambiguous because Foxx also provides adependency mechanism for linking services together.
Use a tool like yarn ornpm tocreate a package.json
file in your service source directory and add nodedependencies as you would for any other Node.js application or library:
cd my-foxx-service/
echo '{"private": true}' > package.json
yarn add lodash # or:
npm install --save lodash
Make sure to include the actual node_modules
folder in your Foxx servicebundle as ArangoDB will not automatically install these dependencies for you.Also keep in mind that bundling extraneous modules like developmentdependencies may bloat the file size of your Foxx service bundle.
If you are using the Foxx CLIcommand-line tool, you can exclude individual modules by ignoring them:
npm install --save prettier
foxx ignore '/node_modules/prettier/'
# the 'prettier' folder will now be excluded
# in service bundles generated by foxx-cli
foxx install /my-foxx-service
Keep in mind that both yarn and npm typically also install dependencies ofyour dependencies to the node_modules
folder which you’ll need to ignore aswell if you want to exclude these modules from your service bundle.
If you are using the npm package manager, you can usenpm install —global-style
to force these indirect dependenciesto be nested to make them easier to exclude.