Would you like the webtask.io experience in your own SaaS? Try


Including Modules

Set up your dependencies


Webtask allows you to use many of the available npm modules. Doing so requires you to first 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.

Webtask Dependencies

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).