Xano Documentation
Search…
⌃K

Libraries & Functions

Lambdas become even more powerful when they can stand on the shoulders of world class libraries and functions developed by 3rd parties. Xano currently doesn't support loading arbitrary external libraries, but we do hand pick the most popular ones based on customer demand. If you have a favorite, then please let us now on our feedback board.

Lodash

The Lodash library is considered the Swiss Army Knife of transformation. If you are tasked with manipulating strings, numbers, objects, and/or arrays, then there is a good chance the lodash library can help.
This library is accessible within the Lambda through the library variable _ (the underscore character).
Here is an example of using the uniq function of the lodash library to return an array of unique values.
var items = [1,2,3,2,1];
return _.uniq(items); // returns a unique array of [1,2,3]

Moment.js

The Moment.js library is a popular library used to parse, validate, transform, and format dates and time.
This library is accessible within the Lambda through the library variable moment .
Here is an example showing how to parse an ISO 8601 formatted date, add 1 month, and then return the result in its original format.
var myDate = '2022-01-01T00:00:00.000Z';
return moment(myDate).add(1, "month").toISOString(); // 2022-02-01T00:00:00.000Z

Luxon

The Luxon library was built by one of the Moment.js's maintainers and is considered the next evolution of Moment.js.
This library is accessible within the Lambda through the library variable luxon.
Here is an example showing how to parse an ISO 8601 formatted date, add 1 month, and then return the result in its original format.
var myDate = '2022-01-01T00:00:00.000Z';
return luxon.DateTime.fromISO(myDate).plus({month: 1}).setZone("UTC").toISO(); // 2022-02-01T00:00:00.000Z

Axios

The Axios library is a popular networking library for sending HTTP requests.
This library is accessible within the Lambda through the library variable axios.
Here is an example showing how to retrieve a json response from GitHub's API.
var url = 'https://api.github.com/users/github';
return (await axios.get(url)).data;

Fetch

The Fetch library is another networking library for sending HTTP requests. It is built into current generation web browsers, which makes it very popular to use because there is no additional download required.
This library is accessible within the Lambda through the library variable fetch.
Here is an example showing how to retrieve a json response from GitHub's API.
var url = 'https://api.github.com/users/github';
return (await fetch(url)).json();

Math.js

The Math.js library provides support for advanced math formulas and expressions.
This library is accessible within the Lambda through the library variable math. The standard JavaScript Math library is accessible through the variable Math, so make sure you pay attention to case sensitivity, so that you are using the appropriate library.
Here is an example showing how to perform the negative square root of 4.
return math.sqrt(-4);
// 2i

Crypto

The Crypto library is built into Node.js and useful for performing common routines related to cryptography.
This library is accessible within the Lambda through the library variable crypto.
Here is an example showing how to perform a SHA 256 digital signature.
var data = 'test123';
return crypto.createHash('sha256').update(data).digest('hex');
// ecd71870d1963316a97e3ac3408c9835ad8cf0f3c1bc703527c30265534f75ae

Nodemailer

The Nodemailer library provides support to send email using SMTP and other transport mechanisms.
This function is accessible within the Lambda through the function variable nodemailer.
Here is an example showing how to send a test email through ethereal.email. This example is taken from the Nodemailer documentation.
let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass, // generated ethereal password
},
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Fred Foo 👻" <[email protected]>', // sender address
to: '[email protected], [email protected]', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>', // html body
});
return nodemailer.getTestMessageUrl(info);
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...

Mailparser

The Mailparser library is an addon for Nodemailer.
This function is accessible within the Lambda through the function variable mailparser.
Here is an example showing how to instantiate it.
const MailParser = mailparser.MailParser;
let parser = new MailParser();
return typeof parser; // object

Promisify

The Promisify function is built into Node.js and is useful for converting legacy callback routines into a Promise based variant. Promises are a standardization of how responses are received in asynchronous programming, which makes it possible to rely on shorthand keywords like async.
This function is commonly used along with the Crypto library for those wishing to use that library with Promises instead of callbacks.
This function is accessible within the Lambda through the function variable promisify.
Here is an example showing how to use Promisify on the Crypto library to generate an HMAC secret key.
return (await promisify(crypto.generateKey)('hmac', {length: 64}))
.export()
.toString('hex');

Node Http/Https

These libraries are built into Node.js and allow you to further customize the http experience. They work both within the Fetch and the Axios library.
They are accessible within the Lambda through the function variable http and https.
Here is an example showing how to create a custom https agent.
const httpsAgent = new https.Agent({
keepAlive: true
});

Ethers.js

This library aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem.
This is accessible within the Lambda through the function variable ethers.
Here is an example of formatting a number in Ether.
return ethers.utils.formatEther(10); // 0.0000000000000001