Managing Digital Assistant node dependencies

Digital Assistant uses global and local npm modules, which allows to efficiently manage dependencies.

To use npm, you need to have Node.js installed locally on your server.

Global modules

There's a small number of dependencies that are used throughout Digital Assistant, therefore we made them globally accessible. These modules are:

  1. agentkeepalive - The Node.js's missing keep alive http.Agent
  2. cookie - Basic HTTP cookie parser and serializer for HTTP servers
  3. got - Simplified HTTP requests
  4. xml2js - Simple XML to JavaScript object converter
  5. mssql - Microsoft SQL Server client for Node.js

You can include these modules, in Javascript file using a require statement e.g. let got = require('got');

Local modules

In addition to global modules your Digital Assistant Components may require additional functionality provided by specific npm libraries. You can install and use these libraries locally within each component. Every Digital Assistant Card comes with a package.json file, which is located in the scripts folder and is used to manage the dependencies:

Package Json file in the scripts folder

Adding a new local dependency

To add a new dependency we can simply open the PowerShell and navigate to the script folder in the Card's directory:

Navigate to the Script directory inside Card's folder

Then, install an additional library with npm install <module name> with --save-dev or --save parameters e.g:

Installing an npm module and saving it as a dependency

The --save and --save-dev parameters specify whether to save the dependency as a production or development level dependency and creates an entry in the package.json file:

Package Json file

This allows to keep a track of used dependencies and ensures that correct packages and versions are used by everyone in the team in case the node_modules folder is modified.

Then, the updated component can be zipped and uploaded to the Workplace Manager.

If you would like to know more about how to download/upload components in Digital Assistant, please have a look at this guide.