Best practices on code seperation?

I have a webhook that reacts to a service and does 3-4 main things, each with its own helper functions. It’s about 300 lines long at this point and getting hard to read.

I was wondering if there are any best practices for separating out the code - In my own Node apps, usually, I’d make a module / class to contain all the helper code and then import that into the webhook logic.

I was thinking about using step exports, where in the first step, I declare all my functions and pin them to steps.trigger.event and then re-use these functions in the later steps.

Can steps.trigger.event store functions, or does it need to be a JSON-serializable object as well?

Making my own NPM package seems a bit heavy-handed and a bit harder to update and add new functionality to than I’d like.

1 Like

@shauntvanweelden steps.trigger.event can also only contain JSON-serializable data (it is also technically a step export from the trigger step).

This issue comes up a lot with others (feel free to add more comments and upvote here) and we don’t have an elegant solution for it, but it’s definitely on our minds.

I could envision a very lean UI in Pipedream settings that allows you to write any Node code and export functions:

const sum = (a, b) => a + b
module.exports = { sum }

Then you might get access to that in a workflow via something like $.functions:

$.functions.sum(2, 2)

What do you think about something like that?

Over a month late, but I think this would be a perfect solve to it @dylburger :slight_smile: