Add External Libraries


Recommended for testing and prototyping only

We recommend users to move any advanced business logic that requires access to external libraries to a serverless function and use the API block to interact with it.

Sometimes you need to use one or more external libraries in a Code Step. Here is an example that uses the Day.js library and the Calendar plugin to transform a date.

In the example below we will translate an ISO formatted date to an easier to understand (human) version.

Here is the code used in the Code Step

// Reset calendarDate value
calendarDate = '';

// Day.js doc >

// Require the Day.js library
const dayjs = requireFromUrl('[email protected]/dayjs.min.js');
// Require the DayJS Calendar plugin
const calendar = requireFromUrl('[email protected]/plugin/calendar.js')

// Extend Day.js with the Calendar plugin 

// Format the response based on presets
calendarDate = dayjs(dayjs(theDate)).calendar(null, {
  sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM )
  nextDay: '[Tomorrow at] h:mm A', // The next day ( Tomorrow at 2:30 AM )
  nextWeek: 'dddd [at] h:mm A', // The next week ( Sunday at 2:30 AM )
  lastDay: '[Yesterday at] h:mm A', // The day before ( Yesterday at 2:30 AM )
  lastWeek: '[Last] dddd [at] h:mm A', // Last week ( Last Monday at 2:30 AM )
  sameElse: 'DD/MM/YYYY' // Everything else ( 17/10/2011 )