Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions docs/docs/code/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,91 @@ export default defineComponent({

Code steps use the same editor ([Monaco](https://microsoft.github.io/monaco-editor/)) used in Microsoft's [VS Code](https://code.visualstudio.com/), which supports syntax highlighting, automatic indentation, and more.




## Sharing data between steps

A Node.js step can use data from other steps using [step exports](/workflows/steps/#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 the `steps` argument passed to the `run({ steps, $ })` function.

In this example, we'll pretend this data is coming into our HTTP trigger via POST request.

```json
{
"id": 1,
"name": "Bulbasaur",
"type": "plant"
}
```

In our Node.js step, we can access this data in the `steps` variable Specifically, this data from the POST request into our workflow is available in the `trigger` property.

```javascript
export default defineComponent({
async run({ steps, $ }) {
const pokemonName = steps.trigger.event.name;
const pokemonType = steps.trigger.event.type;

console.log(`${pokemonName} is a ${pokemonType} type Pokemon`);
}
})
```

### Sending data downstream to other steps

To share data created, retrieved, transformed or manipulated by a step to others downstream you can simply `return` it.

```javascript
// This step is named "code" in the workflow
import axios from 'axios';

export default defineComponent({
async run({ steps, $ }) {
const response = await axios.get("https://pokeapi.co/api/v2/pokemon/charizard");
// Store the response's JSON contents into a variable called "pokemon"
const pokemon = response.data;

// Expose the pokemon data downstream to other steps in the $return_value from this step
return pokemon;
}
})
```

### Using $.export

Alternatively, use the built in `$.export` helper instead of returning data. The `$.export` creates a _named_ export with the given value.

```javascript
// This step is named "code" in the workflow
import axios from 'axios';

export default defineComponent({
async run({ steps, $ }) {
const response = await axios.get("https://pokeapi.co/api/v2/pokemon/charizard");
// Store the response's JSON contents into a variable called "pokemon"
const pokemon = response.data;

// Expose the pokemon data downstream to other steps in the pokemon export from this step
$.export('pokemon', pokemon);
}
})
```

Now this `pokemon` data is accessible to downstream steps within `steps.code.pokemon`

::: warning
Regardless of using `return` or `$.export`, can only export JSON-serializable data from steps. Things like:

* strings
* numbers
* objects
:::


## Passing props to code steps

You can make code steps reusable by allowing them to accept props. Instead of hard-coding the values of variables within the code itself, you can pass them to the code step as arguments or parameters _entered in the workflow builder_.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/code/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ In our Python step, we can access this data in the `exports` variable from the `
from pipedream.script_helpers import (steps, export)

# retrieve the data points from the HTTP request in the initial workflow trigger
name = steps["trigger"]["event"]["name"]
pokemon_name = steps["trigger"]["event"]["name"]
pokemon_type = steps["trigger"]["event"]["type"]

print(f"{pokemon_name} is a {pokemon_type} type Pokemon")
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/workflows/steps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Step exports allow you to pass data between steps. Any data exported from a step

For examples of supported data types in your steps language, see the examples below.

* [Node.js (Javascript)](/code/nodejs/#how-pipedream-node-js-components-work)
* [Node.js (Javascript)](/code/nodejs/#sharing-data-between-steps)
* [Python](/code/python/#sharing-data-between-steps)
* [Bash](/code/bash/#sharing-data-between-steps)
* [Go](/code/go/#sharing-data-between-steps)
Expand Down