npm
Warning
- No technical support: Advantech does not provide technical support for Node.js nodes or packages installed using npm.
- Embedded environment risks: The router is an embedded device with limited resources. Installing packages directly on the router comes with inherent limitations and risks. Read the Node-RED Router App documentation before using this tool — in particular the section on building and installing custom nodes.
- Storage risk: Installing packages to the system partition (
/usr/lib) can fill the available storage and render the router non-functional. A factory reset may not resolve this. - Firmware updates: Packages installed to the system partition are deleted when the router firmware is updated.
Introduction
The npm Router App installs npm (Node Package Manager) — the official package manager for Node.js. It enables managing Node.js modules and packages directly on the router from the command line.
The primary use case on Advantech routers is extending Node-RED with additional nodes and packages. npm can install pure JavaScript nodes directly on the router. Nodes that include native (C/C++) extensions generally cannot be built on the router and must be prepared on a PC with a compatible cross-compilation toolchain first.
Installation
To install the npm Router App, follow the instructions in the Configuration Manual, section Customization → Router Apps.
To verify the installation, check the npm version from the router's CLI:
npm --versionnpm requires an active internet connection to download packages from the npm registry.
Basic Usage
Installing a Package
To install a Node-RED node or any Node.js package globally to /usr/lib/node_modules:
npm install -g <package_name>For example, to install a Node-RED community node:
npm install -g node-red-contrib-combineNode-RED discovers palette nodes installed to /usr/lib/node_modules automatically. Restart Node-RED after installing a new node for it to appear in the palette.
Common Commands
| Command | Description |
|---|---|
npm install -g <package> | Install a package globally. |
npm uninstall -g <package> | Uninstall a globally installed package. |
npm list -g --depth=0 | List all globally installed packages. |
npm update -g <package> | Update a globally installed package. |
npm cache clean --force | Clear the npm cache to free storage space. |
Installation Path
By default, npm install -g installs packages to /usr/lib/node_modules on the system partition. Other locations on the router are symlinks to /opt and may be overwritten during firmware updates. Changing the install location is possible but requires care to ensure Node-RED can still discover the installed nodes.
Limitations on Embedded Routers
Running npm on an embedded router differs significantly from a standard Linux environment:
- Pure JavaScript only: npm can install packages that are written entirely in JavaScript without compilation. These are the most reliably installable packages on the router.
- Native extensions fail: Packages that include C/C++ native extensions (indicated by a
WARN install No prebuilt binaries foundmessage during install) require compilation. The router lacks the necessary build tools, so these packages must be prepared on a PC. - Architecture: Any prebuilt binaries in a package must target the router's CPU architecture (ARM). Binaries compiled for x86 will not run.
- Node.js version compatibility: Packages must be compatible with the Node.js version installed on the router.
- Storage: npm packages and their dependency trees can be large. Monitor available storage carefully. Use
npm cache clean --forceto free space used by the npm download cache.
Preparing Packages on a PC
When a package cannot be installed directly on the router — for example because it requires compilation — it can be prepared on a Linux PC and then copied to the router.
For detailed instructions on preparing both JavaScript-only nodes and nodes with native extensions (including cross-compilation for ARM using the Advantech toolchain), refer to the Building the Custom Nodes for Node.js/Node-RED section in the Node-RED Router App documentation.