Create and deploy a serverless function in Javascript

With the API, you can quickly build a serverless cloud-based function that executes server-side Javascript code.


This template provides a basic example of how to create a serverless function using Javascript. Replace the sample snippet with your own Javascript code and executes it in a container when you run the pipe.

Code template

How it works

When you use a javascript() task in a pipe, executes the Javascript code you specify in a container. Input is passed to the task via standard in and the results are passed back to the pipe via standard out.

In the SDK, this command is a wrapper for the execute task in the API. When javascript() is called, an execute task is added to the pipe that includes a base64-encoded version of the code to be executed, as well as an identifier that indicates the code to be executed is Javascript.

For example, in this template, when the pipe runs, function (context) is called, executing context.output.write('Hello World!'), which writes ‘Hello World!’ to the output. The results are returned to the caller, and echoed to the user interface in a callback function.

Extend it

You can create your own serverless function simply by setting up and saving a pipe with a javascript() task. You can pass any number of parameters to a serverless function, or create it using code on GitHub.

Example 1

To create an API endpoint that invokes a serverless function, save the pipe with an alias:

Best practices for aliases are to use your username as a prefix (e.g. {username}-hello-world)

Later on, you can run pipe in the following manner:

Example 2

Execute a serverless function with parameters sent via the API.

Example 3

Chain together functions to build up processing logic with reusable code building blocks.