### Parse Node-RED Flow from File Source: https://github.com/node-red/flow-parser/blob/main/README.md This snippet demonstrates the basic usage of `@node-red/flow-parser` to load a Node-RED flow JSON from a local file and parse it into a structured object. It shows how to read the file content, parse it as JSON, and then use `parseFlow` to get a manipulable flow object. ```javascript const fs = require("fs"); const { parseFlow } = require("@node-red/flow-parser"); // Load the flow json from a local file and parse to an object const exampleFlow = JSON.parse(fs.readFileSync("flows.json", "utf-8")); // Parse the flow const flow = parseFlow(exampleFlow); // `flow` is now an object that can be used to explore the flow structure ``` -------------------------------- ### Traverse Node-RED Flow Objects with `walk` Source: https://github.com/node-red/flow-parser/blob/main/README.md This example illustrates how to use the `walk` function to iterate over every object within a parsed Node-RED flow. It demonstrates how to identify different types of flow components (Flow, Subflow, Group, ConfigNode, Node) using `FlowParser.types` and perform actions based on their type, providing a structured way to process flow elements. ```javascript const fs = require("fs"); const FlowParser = require("@node-red/flow-parser"); // Load the flow json from a local file and parse to an object const exampleFlow = JSON.parse(fs.readFileSync("flows.json", "utf-8")); const flow = FlowParser.parseFlow(exampleFlow); flow.walk(function(obj) { switch(obj.TYPE) { case FlowParser.types.Flow: // A flow object break; case FlowParser.types.Subflow: // A subflow definition break; case FlowParser.types.Group: // A group object break; case FlowParser.types.ConfigNode: // A config node break; case FlowParser.types.Node: // A flow node break; } }) ``` -------------------------------- ### Export Modified Node-RED Flow Source: https://github.com/node-red/flow-parser/blob/main/README.md This snippet demonstrates how to modify a parsed Node-RED flow and then export the changes back into a standard JSON array format. Specifically, it shows how to use the `walk` function to find and disable all 'debug' nodes within the flow, followed by calling the `export` function to generate the updated flow configuration. ```javascript const flow = parseFlow(exampleFlow); flow.walk(obj => { if (obj.type === 'debug') { obj.active = false; } }); const newFlow = flow.export(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.