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:

  1. cd my-foxx-service/
  2. echo '{"private": true}' > package.json
  3. yarn add lodash # or:
  4. 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:

  1. npm install --save prettier
  2. foxx ignore '/node_modules/prettier/'
  3. # the 'prettier' folder will now be excluded
  4. # in service bundles generated by foxx-cli
  5. 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.