Category Archives: RunSmart

Using NPM packages from RunSmart microservices

The RunSmart workflow environment uses node.js for it’s microservice system, and in addition to the built-in libraries it’s possible to install and use Node Package Manager (NPM) packages. This is incredibly handy, and this post briefly shows how to install these packages and consume them from RunSmart workflow scripts.

Note: It is of course possible pull down the code for npm modules and maintain native RunSmart libraries, and gives tighter control of the code running on your system. In practice however, this becomes a large task with anything than non-trivial npm packages due to the number of package references they tend to use.

Installing NPM Packages

To install npm packages, you’ll need to remote onto the server hosting your Windows Workflow Services installation. From this computer, open a node.js command prompt, and navigate to your installation directory for RunSmart (usually c:\Program Files (x86)\BASELAYER). This is the directory that will be used as the search path for node_modules, and if you look at the contents of this directory you may already have this directory present. If you don’t, no worries as it’ll be created when you install your first package.

To install a package, you can usually just run npm install <package name>. In the screenshot below I’m installing the TeslaJS package, which I use for monitoring my car.

Installing an NPM package to be consumed by RunSmart Workflow microservices

Using NPM Packages in your RunSmart Microservices

From your RunSmart microservice scripts, you can use the normal node.js require statement to bring in your libraries. The library loader will first look for a local (in database) script matching the require statement, and will afterwards search the node_modules directory.

Importing the npm module ‘teslajs’ (line 5 of the microservice script)

That’s all there is to it!