Can I use require and import in the same Node.js code step?

This topic was automatically generated from Slack. You can find the original thread here.

Raymond Camden : i know yall fixed support for using import… but if you use imprt, you can’t use require anymore? ie you cant mix and match?

Dylan Sather : That’s correct. But almost all Node packages should support ESM syntax (import), so often it’s just a matter of converting your require to import: https://pipedream.com/docs/workflows/steps/code/#require-is-not-defined

Raymond Camden : i dont believe my package can do that - but - i can use the import in a step

Raymond Camden : you know offhand if binarydata can be exported from a step?

Dylan Sather : I’d recommend base64 encoding it and decoding it in the next step.

Also give the import a try before you separate into different steps - it’s very common for a module to support both

Raymond Camden : its our (Adobe PDF Services) SDK - I’m 99% sure we don’t :wink:

Raymond Camden : so right now im posting a large b64 string. i have a step that gets the b64 via body.raw_body_url. shoul di export the b64 from the step or the binary conversion? the workflow editor seemed to get angry at that

Raymond Camden : by that i mean - i exported the binary from a step, and i can tell when the editor tries to provide code completion, its hanging hard

Dylan Sather (Pipedream) : Can you instead try to write the data (binary or base64) to a file in /tmp, and reading it in the next step? Working with the filesystem in Node.js

Raymond Camden : i think i’ll need to

Raymond Camden : is there a way to ‘flush’ a workflow editor’s cache? its super laggy now

Dylan Sather (Pipedream) : try deleting all of the prior events (the button at the bottom of the inspector)

Dylan Sather (Pipedream) : btw I don’t mean to push at all, but I got the Node SDK working with import if you want to give it a try: https://pipedream.com/@dylburger/adobe-pdf-services-import-example-p_vQC25jK/edit

Raymond Camden : no you arent pushy :slightly_smiling_face: i was convinced it didnt, glad to be wrong :wink:

Dylan Sather (Pipedream) : I was equally unaware how many modules were published in the “hybrid” (ESM + CJS) manner

Raymond Camden : im going to keep it as require as i like my “suck down the b64, make binary, and store” part is in its own step

Raymond Camden : i know i asked this before, but are writes/reads to /tmp/* unique? the docs say, “For high-volume workflows, data may get retained across workflow executions…”, so if i write to /tmp/foo.txt and read from it, is it possible 2 calls at the same time will get incorrect data? (assuming both write different values to foo.txt)

Dylan Sather (Pipedream) : if you invoke a workflow twice at the same time, each invocation would get its own “execution environment”, and /tmp would be unique to each environment.

The docs refer to the case where you have one invocation, then another one minute later. /tmp will stick around from the first run in that case.

Dylan Sather (Pipedream) : in general, clear /tmp at the end of each run

Raymond Camden : k - so i dont need to make a unique filename