NPM Packages

NPM Packages

Trayce comes with a set of commonly used NPM packages built-in. But also lets you install your own packages in collections.

Trayce supports CommonJS syntax require for importing libraries. ES Modules import/export are not supported at this time.

Inbuilt Packages

Below is the list of inbuilt libraries available:

  • axios - Promise based HTTP client for the browser and node.js
  • atob - Turn base64-encoded ascii data back to binary.
  • btoa - Turn binary data to base64-encoded ascii.
  • chai - BDD/TDD assertion library for node.js and the browser.
  • moment - Parse, validate, manipulate, and display dates and times in JavaScript.
  • uuid - For the creation of RFC4122 UUIDs.
  • nanoid - A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
  • crypto-js - JavaScript library of crypto standards.
  • tv4 - Tiny Validator for JSON Schema v4.
  • node-fetch - A light-weight module that brings Fetch API to Node.js.
  • lodash - A modern JavaScript utility library delivering modularity, performance & extras.
  • ajv - Ajv JSON schema validator.
  • cheerio - Library for parsing and manipulating HTML and XML.
  • xml2js - Simple XML to JavaScript object converter for Node.js.

Here’s an example demonstrating how to use the chai library:

const chai = require('chai');

const { expect } = chai;

function add(a, b) {
  return a + b;
}

const result = add(2, 3);

expect(result).to.equal(5);

console.log('Test passed!');

You can include this code in a pre-request script to test it out.

External Packages

To load your own external packages, you must initialize a package.json file, you can do this by running this within a collection folder.

npm init -y

If you run this in a collection called collection1 then the resulting folder structure will be something like:

      • details.bru
    • .gitignore
    • bruno.json
    • package.json
    • package-lock.json
    • .env
  • You can then add packages as you normally would in a NodeJS project by running npm add <package_name>.