Installing Packages
You can add functionality to your flow by installing Linux or npm packages. The steps to install a package and to protect against upgrades varies, depending on the type of package you plan to install.
Npm packages can be installed in two ways: from the Flow Editor or from the terminal, both described below. After installing a package, it can be called in a function node.
Installing npm packages from the Flow Editor
1. | Open the flow you want to modify in the Flow Editor. |
2. | Add a function node to the flow, then double-click it to edit the node. Or edit an existing function node. |
3. | In the Function text box, enter a comment that includes the npm install command in the form // npm install <package-name> For example: // npm install mathjs |
4. | Deploy the flow. The package is installed and automatically saved to the flow's package.json as a project dependency. This ensures that this module is re-installed when the flow is upgraded. |
After installing the module, the version number of the module is appended to the end of the comment in the function node. For example:
// npm install mathjs@3.5.3
To install a newer package version, update the number listed in the comment, then deploy the flow: the module updates to the version you specified.
Installing npm packages from the terminal
1. | Open a terminal for the flow, then change directory to /home/flow/src/flow - all npm packages must be installed in this directory. If you start from a new terminal window, you can enter cd src/flow to navigate to this directory. |
2. | Enter npm install <package_name> --save Including the --save flag is essential: it adds the specified module as a dependency to your flow’s package.json and ensures that this module is re-installed when the flow is upgraded. For example, to install the npm package left-pad, enter: npm install left-pad --save |
Verifying your flow dependencies
Whether you install npm packages from the Flow Editor or from a terminal, you can check the success of the installation by viewing the contents of the flow's package.json file, located in the flow's /home/flow/src/flow directory.
To view the contents of package.json:
1. | Open a terminal for the flow, then change directory to /home/flow/src/flow. If you start from a new terminal window, you can enter cd src/flow to navigate to this directory. |
2. | To view the contents of the flow's package.json file, enter: cat package.json The contents display in the terminal window. |
For example, if you installed the mathjs npm module, the contents would look something like this:
{
"name": "flow",
"version": "1.0.0",
"description": "",
"dependencies": {
"mathjs": "^3.5.3"
}
}
To view a list of global npm packages available in the flow, open a terminal, and enter: npm list -g --depth=0 |
Several Linux packages are installed with every flow instance. To view a list of all Linux packages currently installed, including your packages plus the default packages, enter: dpkg -l
To install additional Linux packages:
1. | Open a terminal for the flow. |
2. | Enter sudo apt-get install <package-name> For example, to install the package pdftools, enter: sudo apt-get install pdftools |
3. | Add the install line to the flow's upgrade script to ensure that this package is reinstalled when the flow is upgraded: |
|