It’s important to understand the core difference between Node.js and the JavaScript that runs in your web browser: Node doesn’t have access to some of the things a browser expects, like the HTML on the page, or its URL. If you haven’t used Node before, be aware of this limitation as you search for JavaScript examples on the web.
Adding a code step
- Click the + button below any step of your workflow.
- Select the option to Run custom code.
Sharing data between steps
A Node.js step can use data from other steps using step exports, it can also export data for other steps to use.Using data from another step
In Node.js steps, data from the initial workflow trigger and other steps are available in thesteps
argument passed to the run({ steps, $ })
function.
In this example, we’ll pretend this data is coming into our HTTP trigger via POST request.
steps
variable Specifically, this data from the POST request into our workflow is available in the trigger
property.
Sending data downstream to other steps
To share data created, retrieved, transformed or manipulated by a step to others downstream you can simplyreturn
it.
Using $.export
$.export
helper instead of returning data. The $.export
creates a named export with the given value.
pokemon
data is accessible to downstream steps within steps.code.pokemon
You can only export JSON-serializable data from steps. Things like:
- strings
- numbers
- objects
/tmp
directory.Passing props to code steps
firstName
prop. This will allow us to freely enter text from the workflow builder.
firstName
to this particular step only:

How Pipedream Node.js components work
- Pass input to steps using props
- Connect an account to a step
- Issue HTTP responses
- Perform workflow-level flow control, like ending a workflow early
run
method:
- Any asynchronous code within a code step must be run synchronously, using the
await
keyword or with a Promise chain, using.then()
,.catch()
, and related methods. - Pipedream passes the
steps
variable to the run method.steps
is also an object, and contains the data exported from previous steps in your workflow. - You also have access to the
$
variable, which gives you access to methods like$.respond
,$.export
, and more.
this
, which refers to the current step:
this.appName.$auth
.
Logs
You can callconsole.log
or console.error
to add logs to the execution of a code step.
These logs will appear just below the associated step. console.log
messages appear in black, console.error
in red.
console.dir
If you need to print the contents of JavaScript objects, use console.dir
:
Syntax errors
Pipedream will attempt to catch syntax errors when you’re writing code, highlighting the lines where the error occurred in red.While you can save a workflow with syntax errors, it’s unlikely to run correctly on new events. Make sure to fix syntax errors before running your workflow.
Using npm
packages
Just import
it
To use an npm package on Pipedream, simply import
it:
require
it:
import
or require
statements, not both. See this section for more details.
When Pipedream runs your workflow, we download the associated npm package for you before running your code steps.
If you’ve used Node before, you’ll notice there’s no package.json
file to upload or edit. We want to make package management simple, so just import
or require
the module like you would in your code, after package installation, and get to work.
Third-party package limitations
Some packages require access to a web browser to run, and don’t work with Node.js. Often this limitation is documented on the packageREADME
, but often it’s not. If you’re not sure and need to use it, we recommend just trying to import
or require
it.
Other packages require access to binaries or system libraries that aren’t installed in the Pipedream execution environment.
If you’re seeing any issues with a specific package, please let us know and we’ll try to help you make it work.
Pinning package versions
Each time you deploy a workflow with Node.js code, Pipedream downloads the npm packages youimport
in your step. By default, Pipedream deploys the latest version of the npm package each time you deploy a change.
There are many cases where you may want to specify the version of the packages you’re using. If you’d like to use a specific version of a package in a workflow, you can add that version in the import
string, for example:
The behavior of the caret (
^
) operator is different for 0.x versions, for which it will only match patch versions, and not minor versions.CommonJS vs. ESM imports
In Node.js, you may be used to importing third-party packages using therequire
statement:
axios
CommonJS module published to npm. You import CommonJS modules using the require
statement.
But you may encounter this error in workflows:
Error Must use import to load ES Module
This means that the package you’re trying to require
uses a different format to export their code, called ECMAScript modules (ESM, or ES modules, for short). With ES modules, you instead need to import
the package:
import
, you’re less likely to have problems. In general, refer to the documentation for your package for instructions on importing it correctly.
require
is not defined
This error means that you cannot use CommonJS and ESM imports in the same step. For example, if you run code like this:
require is not defined
error. There are two solutions:
- Try converting your CommonJS
require
statement into an ESMimport
statement. For example, convert this:
- If the
import
syntax fails to work, separate your imports into different steps, using only CommonJS requires in one step, and only ESM imports in another.
Variable scope
Any variables you create within a step are scoped to that step. That is, they cannot be referenced in any other step. Within a step, the normal rules of JavaScript variable scope apply. When you need to share data across steps, use step exports.Making HTTP requests from your workflow
There are two ways to make HTTP requests in code steps:- Use any HTTP client that works with Node.js. See this example guide for how to use
axios
to make HTTP requests. - Use
$.send.http()
, a Pipedream-provided method for making asynchronous HTTP requests.
$.send.http()
. If you need to operate on the data in the HTTP response in the rest of your workflow, use axios
.
Returning HTTP responses
You can return HTTP responses from HTTP-triggered workflows using the$.respond()
function.
Invoke another workflow
This is an alpha feature and is subject to change without prior notice.
$.flow.trigger
:
Ending a workflow early
- You may want to end your workflow early if you don’t receive all the fields you expect in the event data.
- You only want to run your workflow for 5% of all events sent from your source.
- You only want to run your workflow for users in the United States. If you receive a request from outside the U.S., you don’t want the rest of the code in your workflow to run.
- You may use the
user_id
contained in the event to look up information in an external API. If you can’t find data in the API tied to that user, you don’t want to proceed.
return $.flow.exit()
will end the execution of the workflow immediately. No remaining code in that step, and no code or destination steps below, will run for the current event.
It’s a good practice to use
return $.flow.exit()
to immediately exit the workflow. In contrast, $.flow.exit()
on its own will end the workflow only after executing all remaining code in the step.$.flow.exit()
:
Errors
Errors raised in a code step will stop the execution of code or destinations that follow.Configuration Error
Throwing aConfigurationError
in a Node.js step will display the error message in a dedicated area.
This is useful for providing feedback during validation of props
. In the example below, a required Header value is missing from the Google Sheets action:

email
prop:
Using secrets in code
Workflow code is private. Still, we recommend you don’t include secrets — API keys, tokens, or other sensitive values — directly in code steps. Pipedream supports environment variables for keeping secrets separate from code. Once you create an environment variable in Pipedream, you can reference it in any workflow usingprocess.env.VARIABLE_NAME
. The values of environment variables are private.
See the Environment Variables docs for more information.
Limitations of code steps
Code steps operate within the general constraints on workflows. As long as you stay within those limits and abide by our acceptable use policy, you can add any number of code steps in a workflow to do virtually anything you’d be able to do in Node.js. If you’re trying to run code that doesn’t work or you have questions about any limits on code steps, please reach out.Editor settings
We use the Monaco Editor, which powers VS Code and other web-based editors. We also let you customize the editor. For example, you can enable Vim mode, and change the default tab size for indented code. Visit your Settings to modify these settings.Keyboard Shortcuts
We use the Monaco Editor, which powers VS Code. As a result, many of the VS Code keyboard shortcuts should work in the context of the editor. For example, you can use shortcuts to search for text, format code, and more.New to JavaScript?
We understand many of you might be new to JavaScript, and provide resources for you to learn the language below. When you’re searching for how to do something in JavaScript, some of the code you try might not work in Pipedream. This could be because the code expects to run in a browser, not a Node.js environment. The same goes for npm packages.I’m new to programming
Many of the most basic JavaScript tutorials are geared towards writing code for a web browser to run. This is great for learning — a webpage is one of the coolest things you can build with code. We recommend starting with these general JavaScript tutorials and trying the code you learn on Pipedream:- JavaScript For Cats
- Mozilla - JavaScript First Steps
- StackOverflow operates a programming Q&A site that typically has the first Google result when you’re searching for something specific. It’s a great place to find answers to common questions.