[{"data":1,"prerenderedAt":334},["ShallowReactive",2],{"node-red-\u002Fnode-red\u002Fcore-nodes\u002Fwrite-file":3},{"id":4,"title":5,"body":6,"description":317,"extension":327,"meta":328,"navigation":329,"path":330,"seo":331,"stem":332,"__hash__":333},"nodeRed\u002Fnode-red\u002Fcore-nodes\u002Fwrite-file.md","Node-RED - Write File Node",{"type":7,"value":8,"toc":316},"minimark",[9,14,19,34,38,130,136,140,143,147,204,208,213,218,224,227,231],[10,11,13],"h1",{"id":12},"write-file","Write File",[15,16,18],"h2",{"id":17},"what-is-the-write-file-node-in-node-red","What is the Write File Node in Node-RED?",[20,21,22,23,28,29,33],"p",{},"The \"Write File\" node in Node-RED is used to write data to a file on the filesystem. It's commonly employed in flows where you need to save data or logs for later analysis or storage. In FlowFuse Cloud, the Write File node interacts with a cloud-based storage solution, leveraging AWS S3 for file storage. However, in the Node-RED instance running on edge devices using the ",[24,25,27],"a",{"href":26},"\u002Fplatform\u002Fdevice-agent\u002F"," FlowFuse device agent",", this node will interact with the local file system of that device. The content to be written is specified using ",[30,31,32],"code",{},"msg.payload",".",[10,35,37],{"id":36},"configuring-the-write-file-node-in-node-red","Configuring the Write File Node in Node-RED:",[39,40,41,82,108,114,120],"ul",{},[42,43,44,48,49],"li",{},[45,46,47],"strong",{},"Filename:"," Specify the filename",[39,50,51,57,70,76],{},[42,52,53,56],{},[45,54,55],{},"Path:"," Specify the path to the file where data will be saved.",[42,58,59,62,63,66,67,69],{},[45,60,61],{},"msg:"," Use a message property to dynamically set the filename, By default, it will use ",[30,64,65],{},"msg.filename",", and if ",[30,68,65],{}," is used, the file will be closed after every write. For the best performance, use a fixed filename.",[42,71,72,75],{},[45,73,74],{},"Expression:"," Use a JSON expression to set the filename dynamically based on data in the flow.",[42,77,78,81],{},[45,79,80],{},"Environment Variable (env var):"," Use an environment variable to set the filename dynamically.",[42,83,84,87,88],{},[45,85,86],{},"Action:"," Choose the action",[39,89,90,96,102],{},[42,91,92,95],{},[45,93,94],{},"Append to File:"," Adds new data to the existing file.",[42,97,98,101],{},[45,99,100],{},"Overwrite File:"," Replaces the content of the file with new data.",[42,103,104,107],{},[45,105,106],{},"Delete File:"," Removes the specified file from the filesystem.",[42,109,110,113],{},[45,111,112],{},"Add Newline (\\n) to Each Payload:"," Enabling this option will append a newline character to each payload before writing to the file.",[42,115,116,119],{},[45,117,118],{},"Create Directory if it Doesn't Exist:"," Enabling this option will create the specified directory if it is not already present in the filesystem.",[42,121,122,125,126,129],{},[45,123,124],{},"Encoding:"," Specifies the character encoding to be used when writing data to the file, when selecting \"set by ",[30,127,128],{},"msg.encoding","\" you can set it dynamically.",[20,131,132],{},[133,134,135],"em",{},"Tip: Always use an absolute path for the filename to ensure Node-RED can accurately locate and manipulate the specified file.",[15,137,139],{"id":138},"output","Output",[20,141,142],{},"After the completion of the write operation, the input message passed to the write file node is sent to the output port.",[15,144,146],{"id":145},"use-cases","Use Cases",[148,149,150,156,162,168,174,180,186,192,198],"ol",{},[42,151,152,155],{},[45,153,154],{},"Data Logging:"," Store sensor readings, IoT device data, or system metrics into a file for historical analysis or monitoring trends over time.",[42,157,158,161],{},[45,159,160],{},"Error Logging:"," Capture and log error messages, exceptions, or debugging information to a file for troubleshooting and debugging purposes.",[42,163,164,167],{},[45,165,166],{},"User Inputs:"," Save user inputs or form submissions to a file, such as user preferences, feedback, or user-generated content.",[42,169,170,173],{},[45,171,172],{},"Reporting:"," Generate reports in CSV, JSON, or plain text formats and save them to a file for later retrieval or distribution.",[42,175,176,179],{},[45,177,178],{},"Backup and Recovery:"," Create backup files of critical data or system states for disaster recovery or version control purposes.",[42,181,182,185],{},[45,183,184],{},"Integration with External Systems:"," Save data retrieved from APIs, databases, or external services to a file for further processing or analysis.",[42,187,188,191],{},[45,189,190],{},"Archiving:"," Archive log files, historical data, or outdated documents to maintain a record of past events or changes.",[42,193,194,197],{},[45,195,196],{},"Data Transformation:"," Perform data transformation operations and write the transformed data to a file in a different format or structure.",[42,199,200,203],{},[45,201,202],{},"Event Logging:"," Log events, notifications, or user interactions to a file for auditing, compliance, or historical tracking purposes.",[15,205,207],{"id":206},"examples","Examples",[148,209,210],{},[42,211,212],{},"In the example flow below, we demonstrate how to create a file and write content to it.",[214,215],"render-flow",{":height":216,"flow":217},"200","W3siaWQiOiJhYTI0N2ZiMWVmMTYzYzkyIiwidHlwZSI6Imdyb3VwIiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwic3R5bGUiOnsic3Ryb2tlIjoiI2IyYjNiZCIsInN0cm9rZS1vcGFjaXR5IjoiMSIsImZpbGwiOiIjZjJmM2ZiIiwiZmlsbC1vcGFjaXR5IjoiMC41IiwibGFiZWwiOnRydWUsImxhYmVsLXBvc2l0aW9uIjoibnciLCJjb2xvciI6IiMzMjMzM2IifSwibm9kZXMiOlsiYmZiMjkwMzg2OTE1N2UxZiIsIjAxNTAzZjVhNDkzZDAzY2MiLCIyNTM3ZWJjMjc2NDAzNTkxIiwiOGFkNzY2ZTFkNjc0NjZmNCJdLCJ4IjoxOTQsInkiOjE3OSwidyI6NzEyLCJoIjoxNjJ9LHsiaWQiOiJiZmIyOTAzODY5MTU3ZTFmIiwidHlwZSI6ImZpbGUiLCJ6IjoiYjVlYTZkMmEuNmU3YmIiLCJnIjoiYWEyNDdmYjFlZjE2M2M5MiIsIm5hbWUiOiIiLCJmaWxlbmFtZSI6Ii9teWZpbGUudHh0LyIsImZpbGVuYW1lVHlwZSI6InN0ciIsImFwcGVuZE5ld2xpbmUiOnRydWUsImNyZWF0ZURpciI6ZmFsc2UsIm92ZXJ3cml0ZUZpbGUiOiJmYWxzZSIsImVuY29kaW5nIjoibm9uZSIsIngiOjU0MCwieSI6MzAwLCJ3aXJlcyI6W1siMjUzN2ViYzI3NjQwMzU5MSJdXX0seyJpZCI6IjAxNTAzZjVhNDkzZDAzY2MiLCJ0eXBlIjoiaW5qZWN0IiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwiZyI6ImFhMjQ3ZmIxZWYxNjNjOTIiLCJuYW1lIjoiV3JpdGUgaW50byBmaWxlIiwicHJvcHMiOlt7InAiOiJwYXlsb2FkIn1dLCJyZXBlYXQiOiIiLCJjcm9udGFiIjoiIiwib25jZSI6ZmFsc2UsIm9uY2VEZWxheSI6MC4xLCJ0b3BpYyI6IiIsInBheWxvYWQiOiIiLCJwYXlsb2FkVHlwZSI6ImRhdGUiLCJ4IjozMTAsInkiOjMwMCwid2lyZXMiOltbImJmYjI5MDM4NjkxNTdlMWYiXV19LHsiaWQiOiIyNTM3ZWJjMjc2NDAzNTkxIiwidHlwZSI6ImRlYnVnIiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwiZyI6ImFhMjQ3ZmIxZWYxNjNjOTIiLCJuYW1lIjoiZGVidWcgMSIsImFjdGl2ZSI6dHJ1ZSwidG9zaWRlYmFyIjp0cnVlLCJjb25zb2xlIjpmYWxzZSwidG9zdGF0dXMiOmZhbHNlLCJjb21wbGV0ZSI6ImZhbHNlIiwic3RhdHVzVmFsIjoiIiwic3RhdHVzVHlwZSI6ImF1dG8iLCJ4Ijo4MDAsInkiOjMwMCwid2lyZXMiOltdfSx7ImlkIjoiOGFkNzY2ZTFkNjc0NjZmNCIsInR5cGUiOiJjb21tZW50IiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwiZyI6ImFhMjQ3ZmIxZWYxNjNjOTIiLCJuYW1lIjoiV3JpdGUgdGltZXN0YW1wcyB0byB0aGUgbXlmaWxlLnR4dCBmaWxlLiBJZiB0aGUgZmlsZSBkb2Vzbid0IGV4aXN0LCBpdCB3aWxsIGJlIGNyZWF0ZWQuIiwiaW5mbyI6IiIsIngiOjU1MCwieSI6MjIwLCJ3aXJlcyI6W119XQ==",[148,219,221],{"start":220},2,[42,222,223],{},"In the example flow below, we demonstrate how to delete a file using the Write File node.",[214,225],{":height":216,"flow":226},"W3siaWQiOiJiNWVhNmQyYS42ZTdiYiIsInR5cGUiOiJ0YWIiLCJsYWJlbCI6Im9wZW5WYWx2ZSIsImRpc2F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uY2VEZWxheSI6MC4xLCJ0b3BpYyI6IiIsInBheWxvYWQiOiIiLCJwYXlsb2FkVHlwZSI6ImRhdGUiLCJ4IjozMDAsInkiOjMwMCwid2lyZXMiOltbImJmYjI5MDM4NjkxNTdlMWYiXV19LHsiaWQiOiIyNTM3ZWJjMjc2NDAzNTkxIiwidHlwZSI6ImRlYnVnIiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwiZyI6ImFhMjQ3ZmIxZWYxNjNjOTIiLCJuYW1lIjoiZGVidWcgMSIsImFjdGl2ZSI6dHJ1ZSwidG9zaWRlYmFyIjp0cnVlLCJjb25zb2xlIjpmYWxzZSwidG9zdGF0dXMiOmZhbHNlLCJjb21wbGV0ZSI6ImZhbHNlIiwic3RhdHVzVmFsIjoiIiwic3RhdHVzVHlwZSI6ImF1dG8iLCJ4Ijo4MDAsInkiOjMwMCwid2lyZXMiOltdfSx7ImlkIjoiOGFkNzY2ZTFkNjc0NjZmNCIsInR5cGUiOiJjb21tZW50IiwieiI6ImI1ZWE2ZDJhLjZlN2JiIiwiZyI6ImFhMjQ3ZmIxZWYxNjNjOTIiLCJuYW1lIjoiRGVsZXRpbmcgbXlmaWxlLnR4dCB1c2luZyB3cml0ZSBmaWxlIG5vZGUiLCJpbmZvIjoiIiwieCI6NTUwLCJ5IjoyMjAsIndpcmVzIjpbXX1d",[15,228,230],{"id":229},"node-documentation","Node Documentation",[232,233,236,242,243,242,248],"div",{"className":234},[235],"core-node-doc",[20,237,238,239,241],{},"Writes ",[30,240,32],{}," to a file, either adding to the end or replacing the existing content.\nAlternatively, it can delete the file."," ",[244,245,247],"h3",{"id":246},"inputs","Inputs",[249,250,253,265,272,279],"dl",{"className":251},[252],"message-properties",[254,255,258,259],"dt",{"className":256},[257],"optional","filename ",[260,261,264],"span",{"className":262},[263],"property-type","string",[266,267,268,269,271],"dd",{},"The name of the file to be updated can be provided in the node configuration, or as a message property. \nBy default it will use ",[30,270,65],{}," but this can be customised in the node.\n",[254,273,275,276],{"className":274},[257],"encoding ",[260,277,264],{"className":278},[263],[266,280,281,282,285,288,292,295,301,304,307,310],{},"If encoding is configured to be set by msg, then this optional property can set the encoding.\n",[244,283,139],{"id":284},"output-1",[20,286,287],{},"On completion of write, input message is sent to output port.",[244,289,291],{"id":290},"details","Details",[20,293,294],{},"Each message payload will be added to the end of the file, optionally appending\na newline (\\n) character between each one.",[20,296,297,298,300],{},"If ",[30,299,65],{}," is used the file will be closed after every write.\nFor best performance use a fixed filename.",[20,302,303],{},"It can be configured to overwrite the entire file rather than append. For example,\nwhen writing binary data to a file, such as an image, this option should be used\nand the option to append a newline should be disabled.",[20,305,306],{},"Encoding of data written to a file can be specified from list of encodings.",[20,308,309],{},"Alternatively, this node can be configured to delete the file.",[311,312,315],"script",{"type":313,"dataHelpName":314},"text\u002Fhtml","file in","\n\u003Cp>Reads the contents of a file as either a string or binary buffer.\u003C\u002Fp>\n\u003Ch3>Inputs\u003C\u002Fh3>\n\u003Cdl class=\"message-properties\">\n\u003Cdt class=\"optional\">filename \u003Cspan class=\"property-type\">string\u003C\u002Fspan>\u003C\u002Fdt>\n\u003Cdd>The name of the file to be read can be provided in the node configuration, or as a message property. \nBy default it will use \u003Ccode>msg.filename\u003C\u002Fcode> but this can be customised in the node.\n\u003C\u002Fdd>\n\u003C\u002Fdl>\n\u003Ch3>Outputs\u003C\u002Fh3>\n\u003Cdl class=\"message-properties\">\n\u003Cdt>payload \u003Cspan class=\"property-type\">string | buffer\u003C\u002Fspan>\u003C\u002Fdt>\n\u003Cdd>The contents of the file as either a string or binary buffer.\u003C\u002Fdd>\n\u003Cdt class=\"optional\">filename \u003Cspan class=\"property-type\">string\u003C\u002Fspan>\u003C\u002Fdt>\n\u003Cdd>If not configured in the node, this optional property sets the name of the file to be read.\u003C\u002Fdd>\n\u003C\u002Fdl>\n\u003Ch3>Details\u003C\u002Fh3>\n\u003Cp>The filename should be an absolute path, otherwise it will be relative to\nthe working directory of the Node-RED process.\u003C\u002Fp>\n\u003Cp>On Windows, path separators may need to be escaped, for example: \u003Ccode>\\\\Users\\\\myUser\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>Optionally, a text file can be split into lines, outputting one message per line, or a binary file\nsplit into smaller buffer chunks - the chunk size being operating system dependant, but typically 64k (Linux\u002FMac) or 41k (Windows).\u003C\u002Fp>\n\u003Cp>When split into multiple messages, each message will have a \u003Ccode>parts\u003C\u002Fcode>\nproperty set, forming a complete message sequence.\u003C\u002Fp>\n\u003Cp>Encoding of input data can be specified from list of encodings if output format is string.\u003C\u002Fp>\n\u003Cp>Errors should be caught and handled using a Catch node.\u003C\u002Fp>\n",{"title":317,"searchDepth":220,"depth":220,"links":318},"",[319,320,321,322,323],{"id":17,"depth":220,"text":18},{"id":138,"depth":220,"text":139},{"id":145,"depth":220,"text":146},{"id":206,"depth":220,"text":207},{"id":229,"depth":220,"text":230,"children":324},[325],{"id":246,"depth":326,"text":247},3,"md",{},true,"\u002Fnode-red\u002Fcore-nodes\u002Fwrite-file",{"title":5,"description":317},"node-red\u002Fcore-nodes\u002Fwrite-file","zi0HSMSl2sUdPo9XkFRVq49T4t4q-vB1isljcz0UDAY",1780070556381]