If you want to save a flow or function and reuse it later in another flow on the same computer then you can save it to the local library.
To save a flow to the library highlight all nodes in the flow by using CTRL+A then use the main menu (top right) and select Export>Library.
You will need to give the flow a name and optionally you can create a folder for the flow.
All flows are stored in the lib/flows folder under the users .node-red folder.
To save a function to the library double click on the function to edit it and click on the bookmark icon next to the function name.
A drop down menu appears to either import or save the function to the library.
You need to give the file a name and optionally a folder to store it in.
Note: The function itself should have a name as you will need this when importing the function.
If you don’t give the function a name it appears as an unnamed function when importing.
Using Library Functions and Flows
To use a library flow use the Import>Library option and select the flow, and it appears in the flow canvas
To use a library function drag a function node into the flow canvas then open it for editing.
Click on the bookmark icon next to the function name and select open library from the drop down menu.
Open folder containing functions and the functions appear by name. Select the function and click load, to load the library code into the function.
Video – How to Copy Nodes and Flows in Node-Red -Includes Using the Library
Common Questions and Answers
Q -Can’t I just export the flow to the clipboard and copy it to a text file?
A- Yes but it isn’t as convenient as using libraries when working on the same workspace.
Q- Can I use libraries to copy flows between computers?
A- Yes but it isn’t as easy as using the export clipboard option?
Q- Can I share my library files with others.?
A- Yes you would need to copy the lib folder which is under your .node-red folder.
- Using the Node-Red Function Node- Beginners Guide
- Storing Data in Node-Red Variables
- Understanding and Using The Node-Red Message Object
- Working With Time- Node-Red Programming
- Node-Red Message and Object Cloning
Is there a way to use ‘library functions’ as REAL library functions ?
With that I mean not COPYING the code from the ‘library function’ but USING the saved code so if you change the saved code all function nodes created from that library function are changed automatically as well.
You can use a subflow to do that. A subflow can consists of a single function node and would do what you want but I know what you mean about the term library.