# Writing using file node UTF-8, encoding becomes iso-8859

**URL:** <https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114>\
**Category:** General\
**Created:** [18 March 2019 10:34 UTC](https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114 "2019-03-18T10:34:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbot/32/20140_2.png) [@mbot](https://discourse.nodered.org/u/mbot)\
**Post date:** [18 March 2019 10:34 UTC](https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114/1 "2019-03-18T10:34:54Z")

</div>

I used the file node to write an XML file to disk. The XML has UTF-8 special characters like ä, however when written to file it is written as iso-8859, as shown on the linux command line :  
file original\_alert.xml  
original\_alert.xml: XML 1.0 document, ISO-8859 text, with very long lines

I am running:  
Linux debian 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86\_64 GNU/Linux

locale  
LANG=en\_US.UTF-8  
LANGUAGE=en\_US.UTF-8  
LC\_CTYPE="en\_US.UTF-8"  
LC\_NUMERIC="en\_US.UTF-8"  
LC\_TIME="en\_US.UTF-8"  
LC\_COLLATE="en\_US.UTF-8"  
LC\_MONETARY="en\_US.UTF-8"  
LC\_MESSAGES="en\_US.UTF-8"  
LC\_PAPER="en\_US.UTF-8"  
LC\_NAME="en\_US.UTF-8"  
LC\_ADDRESS="en\_US.UTF-8"  
LC\_TELEPHONE="en\_US.UTF-8"  
LC\_MEASUREMENT="en\_US.UTF-8"  
LC\_IDENTIFICATION="en\_US.UTF-8"  
LC\_ALL=en\_US.UTF-8

And here the code:

`[{"id":"72d46eda.d53ee","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ea39c940.9e1328","type":"inject","z":"72d46eda.d53ee","name":"Create alert","topic":"","payload":"{\"alert\":{\"$\":{\"xmlns\":\"urn:oasis:names:tc:emergency:cap:1.2\"},\"identifier\":[\"httpPost.128.Alert\"],\"sender\":[\"public-warning-portal@one2many.eu\"],\"sent\":[\"2019-02-14T09:35:30+01:00\"],\"status\":[\"Actual\"],\"msgType\":[\"Alert\"],\"source\":[\"SYSTEM\"],\"scope\":[\"Public\"],\"info\":[{\"language\":[\"fi-FI\"],\"category\":[\"Safety\"],\"event\":[\"Alert\"],\"urgency\":[\"Immediate\"],\"severity\":[\"Extreme\"],\"certainty\":[\"Observed\"],\"effective\":[\"2019-02-14T09:35:30+01:00\"],\"expires\":[\"2019-02-14T09:40:30+01:00\"],\"senderName\":[\"Group for system-wide operations. Do not remove.\"],\"headline\":[\"Öljysäiliö on tulessa Turun satamassa\"],\"description\":[\"Tulipalo aiheuttaa myrkyllistä savua, joka kulkeutuu Turun yllä. On suositeltavaa, että suljette kaikki ikkunat ja ovet. Viestin on lähettänyt Varsinais-Suomen hätäkeskus.\"],\"area\":[{\"areaDesc\":[\"Somewhere in the country\"],\"polygon\":[\"52.26929376035382,6.095581491740518 52.22725450454942,6.175232370646768 52.2449158438951,6.304321726115518 52.283578033962094,6.216431101115518\"]}]}]}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":280,"wires":[["4cee15f0.c2d79c"]]},{"id":"4cee15f0.c2d79c","type":"xml","z":"72d46eda.d53ee","name":"","property":"payload","attr":"","chr":"","x":270,"y":280,"wires":[["c227b5d9.ea38e","7ced047d.8f5624"]]},{"id":"c227b5d9.ea38e","type":"function","z":"72d46eda.d53ee","name":"write","func":"var fs = global.get(\"fs\");\nfs.writeFileSync(\"test_alert.xml\",msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":320,"wires":[[]]},{"id":"7ced047d.8f5624","type":"file","z":"72d46eda.d53ee","name":"","filename":"/home/bitnami/original_alert.xml","appendNewline":true,"createDir":false,"overwriteFile":"true","x":530,"y":240,"wires":[[]]}]`

I found that I could overcome this by writing function in using node.js with fs and this seems to write UTF-8 correctly. But nevertheless I thought to share this issue with you.

And versions:  
18 Mar 14:47:04 - [info] Node-RED version: v0.19.5  
18 Mar 14:47:04 - [info] Node.js version: v11.7.0

Now I hope my first post is correct! 🙂

---

<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:** [18 March 2019 10:50 UTC](https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114/2 "2019-03-18T10:50:22Z")

</div>

> [@mbot](#):
>
> Now I hope my first post is correct!

Not quite 🙂 , to make your flow importable you have to follow these instructions:

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![elmicha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/elmicha/32/6678_2.png) [@elmicha](https://discourse.nodered.org/u/elmicha)\
**Post date:** [18 March 2019 22:24 UTC](https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114/3 "2019-03-18T22:24:44Z")

</div>

This was broken in 0.19.5 and fixed in [0.19.6](https://github.com/node-red/node-red/releases/tag/0.19.6). Current is [0.20.2](https://github.com/node-red/node-red/releases).

---

<div class="post-metadata">

**Author:** ![mbot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbot/32/20140_2.png) [@mbot](https://discourse.nodered.org/u/mbot)\
**Post date:** [19 March 2019 08:44 UTC](https://discourse.nodered.org/t/writing-using-file-node-utf-8-encoding-becomes-iso-8859/9114/4 "2019-03-19T08:44:03Z")

</div>

Thanks @elmicha. I've upgraded node-red to 0.20.2 and indeed the problem was fixed!
