# How to Send a STRING/JSON to a .txt File on another PC

**URL:** <https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208>\
**Category:** General\
**Created:** [16 August 2024 06:47 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208 "2024-08-16T06:47:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 06:47 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/1 "2024-08-16T06:47:52Z")

</div>

Hi, i'm a bit new to Node-RED and i was asked a question by a customer: Can I set up some way to store (Locally on their PC) a backup log of the JSON Strings that is sent to their DB in case something happens and i had a thought to send a copy of that String to a .txt file but i cannot seem to figure it out.  
How it goes is PLC does its jobs, marks a product, Sends out JSON String to DB if it was Good or Bad etc.  
Using a CtrlX PLC with Node-RED addon with an IXON Network Switch for remote connection

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 07:45 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/2 "2024-08-16T07:45:20Z")

</div>

![NodeRED_Test](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4192e5ad0e124ee0e31d28d523a109bba4d9879e.jpeg)

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [16 August 2024 08:06 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/3 "2024-08-16T08:06:57Z")

</div>

I use write file node along with a template node in parallel to mysql database update, in case mysql server is shutdown for any reason.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e506b323586e5ab637fc4076501d89a1a5edc35.png)

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 08:23 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/4 "2024-08-16T08:23:55Z")

</div>

How did you use the Write Node? I routed mine like this: "192.168.120:9200\C:\Users\CustomerPC\Desktop\MarkingResults.txt"  
Tried without the IP but i still cannot get it to Write into the .txt file

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [16 August 2024 08:29 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/5 "2024-08-16T08:29:21Z")

</div>

> [@DaVizzey](#):
>
> 192.168.120

Is not a valid IPv4 address.

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 08:33 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/6 "2024-08-16T08:33:58Z")

</div>

you are absolutely correct, missed the subnet number, my bad, will make the change and test it

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [16 August 2024 08:35 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/7 "2024-08-16T08:35:35Z")

</div>

Don't feel bad...I make that kind of error WAY too often, hence my username. 🙄

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 08:38 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/8 "2024-08-16T08:38:21Z")

</div>

Fair enough haha but i made the IP change, no difference text file still empty, The Inject node contains the same type of info as the PLC would send out:  
insert results (art\_brand ,serial\_nr ,time\_marking ,result\_laser\_marking ,mo\_nr,charge ) values ('20239112-0500','Z24210001',GETDATE(),'Ok','000000000','Not Used')

Been thinking if i have to use some kind os Conversion Node to make the Text file happy?

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [16 August 2024 08:48 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/9 "2024-08-16T08:48:31Z")

</div>

Add a Debug node to the output of the TCP Request node. Configure it like this so you can see what you're sending to the file write node.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e25709701b2e31578f54a738b11a54db1d24d5c8.png)

EDIT: It would also be helpful if you post an image of the file write node properties like I did for the debug node.

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 08:53 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/10 "2024-08-16T08:53:58Z")

</div>

Yes sir, give me one sec to set up the debug Node, until then here is an image of the Write Properties

 ![NR1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e67ad39380a559d7cdd1c467c5bdf462a972b2f6.jpeg)

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [16 August 2024 08:56 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/11 "2024-08-16T08:56:30Z")

</div>

In the Filename, remove everything up to "C:..." to get a valid path/file.

EDIT: Sorry, should have noticed that first.

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 09:07 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/12 "2024-08-16T09:07:05Z")

</div>

Well, Idk what happened, had to cut the power real quick as the other machine we got to the same customer needed power real quick, plugged it back in, boot is fine and Node-Red is green... except the PC that is on but it cannot connect through Node-Red now, this is starting to e a interesting friday lol

EDIT: yes i closed down the PC properly before anyone asks haha

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 11:11 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/14 "2024-08-16T11:11:27Z")

</div>

Alrighty Update: Everything is back up and running, found that the TCP Port is for a certain software so i cannot use that to Write To a file, Removed that and inserted the Fix LosinIt recommended, still no sucess sadly. The New File Path is as follows:  
C:\Users\CustomerPC\Desktop\MarkingResults.txt

 ![NR2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/887c791a4cd128f35cd9bd1c80601efb5ec7c6c9.jpeg)  
 ![NR3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b08a124f571cff774b51dcf714a9e7357804301e.jpeg)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [16 August 2024 13:20 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/15 "2024-08-16T13:20:36Z")

</div>

Can you clarify if the file you want to write is on the same PC as Node-red?

> [@DaVizzey](#):
>
> C:\Users\CustomerPC\Desktop\MarkingResults.txt

Does it work if you setup the write file node with  
C:/Users/CustomerPC/Desktop/MarkingResults.txt (ie Unix rather than Dos style slash character)

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [16 August 2024 13:26 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/16 "2024-08-16T13:26:25Z")

</div>

As i put in the topic header, Node-RED is on a CtrlX-PLC (Bosch PLC) and is run through their Web-server system, the PC is External to that system but still on the same machine, connected to the PLC through EtherCAT bus

EDIT: this is what happens with the solution you wanted me to try  
 ![NR4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2877f199d713040b1b9c4f9959384cac9b7c77f.jpeg)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [16 August 2024 13:32 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/17 "2024-08-16T13:32:59Z")

</div>

Sadly I know nothing about CtrlX-PLC, EtherCATs or multiple devices on the same machine.

However, it seems unsurprising that you can't access a user's home folder from another [virtual?] machine without setting up shared folders, NAS, FTP, SSHFS etc.

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [19 August 2024 06:24 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/18 "2024-08-19T06:24:43Z")

</div>

Well, i still got no sucess on getting this to work. The Node-RED instance is fully virtual unlike the PC i want to thransfer the String to. Been thinking if i'd try to use one of the Link Nodes? could that work theoretically?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [19 August 2024 06:51 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/19 "2024-08-19T06:51:31Z")

</div>

The easiest way to get this to work is have the Virtual Machine that is running NR mount the drive of the machine you wish to write to.

Presumably you know how to share out a directory/folder on Windows and make it available ??

1. Create a new user on the windows PC and assing it a password
2. Ensure file sharing is turned on and enabled
3. go to the directory you want to share on windows in File Manager/Explorer and Right click and then choose share this folder - you should be able to select the user you created it will look something like this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7528bef8304b0408899ef9f53aeee3ffa6ec723b.png)

Then on the NR box create a directory to mount it to - usually by convention in the /mnt folder

so maybe a directory with the name

mkdir /mnt/windows

make sure the user that is running Node Red has permission to read and write to this folder

(chown and chmod)

Then mount the windows shared directory into that folder

The command will look something like this

//windowsIPAddrress/sharedfolder /mnt/windows cifs credentials=/etc/win-credentials,iocharset=utf8,sec=ntlmv2 0 0

That is the command you can put into your FSTab file so this will be available each time the machine is restarted.

Craig

---

<div class="post-metadata">

**Author:** ![DaVizzey](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@DaVizzey](https://discourse.nodered.org/u/DaVizzey)\
**Post date:** [19 August 2024 08:48 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/20 "2024-08-19T08:48:45Z")

</div>

the Machine NR is on is a PLC, not an actual Virtual Machine, so i cannot acesss a NR Box or have an User Run NR as it is run automatically when the PLC is booted.  
 ![NR5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/3389c5f01993559437440f605631cd40e3963a31.jpeg)  
As i do Appreciate the replies i get, i don't think this can work from my undestanding that it is possible with this instance of Node-RED. It is not a Virtual Machine, they way i acess this is by directly putting in the PLC:s IP and connecting through a web browser, it does nor run off a standard PC.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 August 2024 09:09 UTC](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208/21 "2024-08-19T09:09:14Z")

</div>

In that case you could use MQTT. Install node red and mosquitto on the PC, connect to mosquitto from the PLC using the MQTT nodes, and pass the required data across. Then in node-red in the PC pick up the data and write the files.

If you don't know about MQTT then see this tutorial [MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)

[Next page](https://discourse.nodered.org/t/how-to-send-a-string-json-to-a-txt-file-on-another-pc/90208.md?page=2)
