🚀 Optimize Code Usage
While the Code Piece offers great flexibility, it should be used judiciously.
Prefer Native Pieces: Always check if a native Utility or Data Helper piece can solve your problem before writing custom code. Native pieces are faster and more resource-efficient.
Avoid Complex Logic in Code: Highly complex algorithms within a Code Piece can significantly increase processing time and memory consumption, risking a flow timeout.
Minimize External Packages: Installing multiple npm packages within a Code Piece adds "weight" to your flow. Only include essential packages that cannot be replaced by simple logic or native tools.
📂 Efficient File Handling (Critical for Stability)
Handling files incorrectly is the #1 cause of "Out of Memory" errors.
❌ Avoid Base64/Buffers: Do not convert files to Base64 strings or large Buffers within your code. Base64 increases file size by ~33%, and processing it in memory can triple the RAM usage, causing the flow to crash.
✅ Use Signed URLs (Streaming): Instead of downloading a file into memory, use the Signed URL provided by Pipefy or the File Utility piece. Your code should "stream" the file directly from the URL to the destination service (e.g., ABBYY, S3, etc.).
✅ Trust Metadata: Use the Content-Type (MIME type) already registered in the storage metadata instead of trying to manually detect or convert file types within the code.
🧩 Modularize with Subflows
If your process is long or handles heavy data (like PDF generation or large file processing), break it into subflows.
Why? Each subflow gets its own fresh set of limits (timeout and memory). This prevents a single long flow from "starving" for resources and failing halfway through.
Benefit: Smaller flows are easier to debug, maintain, and reuse across different projects.
🛡️ Implement Validations & Error Handling
Don't let your flows fail blindly.
Pre-flight Checks: Use a Router (Branch) to validate data before making an expensive HTTP request. Ensure mandatory fields are present and correctly formatted.
Handle API Errors: Always design your flow to handle non-200 responses from external APIs. Use conditional logic to manage errors gracefully instead of letting the entire flow crash.
Handle Errors Gracefully: If the success of your flow is essential, employ the 'Continue on Failure' setting and establish a recovery path to manage the error effectively.
Delay: To maintain platform stability, all flow executions are subject to a 10-minute hard timeout. If your integration interacts with systems that require significant processing time, keeping the connection open will result in a timeout error. The solution is to use the Delay Utility, instead of waiting actively
💾 Smart Memory Management
Avoid Large Polling: When fetching logs or data, only request new or incremental information. Storing massive datasets in memory during a flow execution is the fastest way to hit the memory limit.
Streamline File Handling: Use native storage utilities to handle files via signed URLs rather than processing large base64 strings directly in code pieces.
3. Summary Checklist for Success
Can I replace this Code Piece with a native Data Helper?
Is my flow likely to run for more than 10 minutes? (If yes, use subflows).
Am I validating input data before sending it to an external API?
Are my file attachments under 10 MB?
Am I only installing essential packages in my Javascript steps?
