Using external Node libraries

External Libraries

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

Finding Libraries

  1. Visit the npm website, the package manager for JavaScript and the world's largest software registry.

  2. Search for a package, for example "XML parsing" to find libraries tailored to your requirements.

  3. Select a library from the search results to view its details page.

  4. Locate the version number in the Versions tab. It is recommended to use the most recent stable version listed.

  5. Copy package name and version number from the Install tab and paste them as "package": "version" in the JSON packages configuration.

Libraries dependent on the fs and child_process modules are currently not supported.

Using Libraries in Your Code

Use import statements to include the libraries in your automations:

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 Automations runtime. Please 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