Using external Node libraries

External libraries enhance the functionality of your UI Bakery app by allowing you to use additional JavaScript code. You can take advantage of a vast number of JavaScript libraries to bring date manipulation, data parsing, and much more into your automations.

Finding libraries

  1. Go to the npm website and search for a package, for example XML parsing, to find the libraries you need.

  2. Select a library from the search results to view its Details page.

  3. Click on the Versions tab at the top.

It is recommended to use the most recent stable version listed.

  1. Here, copy the package name and version number and paste them in the Packages tab of the Automations page in the following format:

"xml2js": "^0.6.2"

Using libraries in your code

After adding the package number and version, you simply need to use import statements to include the library in your Automations. Below is an example of an xml2js library added to the Automation action:

import { parseString } from 'xml2js';

// Or use result of other steps, for example, HTTP request as const xml = {{data}}
const xml = `<note>
  <to>User</to>
  <from>Library</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>`;

return new Promise((resolve, reject) => {
  parseString(xml, (err, result) => {
    if (err) {
      reject(err);
    } else {
      resolve(result);
    }
  });
});

require() imports

require() imports are not supported in the Automations runtime. You should use the ES6 module import syntax instead. For modules using CommonJS require, replace it with an ES6 import statement.

Before:

const yaml = require('js-yaml');

After:

import yaml from 'js-yaml';

Last updated

Was this helpful?