Webtask

Documentation

Including Modules

Set up your dependencies, or choose from 1000+ pre-installed modules!

Overview

Webtask allows you to use many of the available npm modules. There are two ways that you can specify modules for your tasks. The first is to set up your Webtask dependencies using a package.json. This will allow you to include almost any module that has been published to the npm registry. The second way to include modules is to require one of the hundreds of pre-installed modules. Although this is a limited pool, if you need a specific module and version that are pre-installed, they are extremely simple to use - they can just be required and used with no other needed actions!

Webtask Dependencies

In many cases, even with the hundreds of pre-installed modules (and versions of those modules) available, others will be needed. Webtask dependencies allow you to customize what Node modules are available to your Webtask using a package.json. This gives you the ability to add almost any module from the npm registry in seconds.

Using the wt-cli

To get started customizing your Webtask dependencies, install the wt-cli if you have not already done so.

Next, if you don't already have one, create a package.json file similar to the below example. Put the file in the same directory that your webtask.js file is in (or will be created in).

{
 "dependencies": {
   "lodash": "4.x"
 }
}

Note that Webtask will read dependencies from the "dependencies" only, and not from the dev dependencies or others. After your package.json file is created (or if you already had one), create a Webtask (or edit an existing one) next to the package.json file that will read dependencies from it, similarly to the below example.

const _ = require('lodash');
module.exports = (ctx, cb) => {
  // Respond with supported lodash methods
  cb(null, Object.keys(_));
};

Now, when you create or update your task using the wt-cli, since you have a package.json file adjacent to the webtask file, the CLI will automatically add those dependencies to the platform, and create your Webtask with the resolved versions of those dependencies attached to it. Read below for more information about how this works.

How Webtask dependencies work

When the wt-cli detects a package.json adjacent to your Webtask file, several things will happen:

  1. Each dependency in your dependencies will be resolved to determine the best matching version available from the npm registry.
  2. The Webtask cluster will then install any modules that have not previously been installed. If all dependencies are already available, this will be immediate. If there are any issues with the requested dependencies, the creation of the task will fail.
  3. Once all of the dependencies are available, they will be encoded in the wt-node-dependencies metadata property of the Webtask that is being created (or updated).
  4. The Webtask is now created!

Note: The wt-node-dependencies metadata property must contain a JSON encoded object, mapping the packages' names to their absolute versions. In the above example, this would be represented by a wt-node-dependencies metadata property whose value is {"lodash":"4.17.4"} (the latest release of lodash at the time of this writing).

Pre-installed modules

The Webtask runtime already contains hundreds of the most popular Node.js modules. If you need to do a simple require of a module and version that is already pre-installed, you can do so. Search the available modules here.

Versioning

Many of the preinstalled modules are available in multiple versions. You can require a particular version of a module with an extended sytax of require, for example:

var mongo = require('mongodb@2.0.33');

You can check which versions of a particular module are available here.

Pre-installed modules on custom deployments

Custom deployments of the Auth0 Webtask technology have full control over the execution environment and can provide a tailored environment that meets your requirements. Contact us for details at support@auth0.com.