# Convert string to buffer

**URL:** <https://discourse.nodered.org/t/convert-string-to-buffer/60755>\
**Category:** General\
**Created:** [4 April 2022 08:32 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755 "2022-04-04T08:32:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 08:32 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/1 "2022-04-04T08:32:03Z")

</div>

I was playing around with better-sftp contrib node and needed to convert my data (string) to a buffer.

And I couldn't immediately think of how to do that (sans coding)

Best I came up with was to put two Base64 nodes back to back and convert to base64 and then decode back to a buffer.

Any other ways?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2022 09:01 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/2 "2022-04-04T09:01:48Z")

</div>

Knowing your aversion to Function nodes 😜 there is always `node-red-contrib-buffer-parser` - it includes a "buffer maker" node.

![chrome_plPSKCw54A](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab46765dd32a87f40c5ba651dd41f8a4a6d6ed4a.gif)

```auto
[
    {
        "id": "e9afa1b55fbb814c",
        "type": "buffer-maker",
        "z": "4cad319b1add5007",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "string",
                "length": -1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 1894,
        "y": 480,
        "wires": [
            [
                "1f2c64d1ec10e525"
            ]
        ]
    },
    {
        "id": "1dc4a8bae838a5b1",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "hello",
        "payloadType": "str",
        "x": 1730,
        "y": 464,
        "wires": [
            [
                "e9afa1b55fbb814c"
            ]
        ]
    },
    {
        "id": "bc217a8f04132d68",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "bye",
        "payloadType": "str",
        "x": 1730,
        "y": 496,
        "wires": [
            [
                "e9afa1b55fbb814c"
            ]
        ]
    },
    {
        "id": "1f2c64d1ec10e525",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 2074,
        "y": 480,
        "wires": []
    }
]

```

However, if you want to avoid a contrib node, let me know & I will share the 1 line of JS 😆

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 09:06 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/3 "2022-04-04T09:06:36Z")

</div>

I think I'm coming around to thing of a feature request to get the change node to have conversion options in it

e.g. number \<\> string, string \<\> buffer/array

Or maybe I just need to do a PR on the better-sftp node to handle string input and convert internally 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 09:08 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/4 "2022-04-04T09:08:34Z")

</div>

> [@Steve-Mcl](#):
>
> I will share the 1 line of JS

One day I must introduce to to a wonderful low-code programming environment designed for people not to have to learn the worst programming language of all time 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 09:12 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/5 "2022-04-04T09:12:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 April 2022 10:42 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/6 "2022-04-04T10:42:35Z")

</div>

> [@cymplecy](#):
>
> the worst programming language of all time

🤣 Obviously, you never had the joy of LISP, Prolog, C and IBM370 assembly!

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 10:53 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/7 "2022-04-04T10:53:21Z")

</div>

And now I need that shelf category for my own thread! 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [4 April 2022 10:54 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/8 "2022-04-04T10:54:01Z")

</div>

Come on folks - answer the OP - are there any no-code alternatives using core nodes? 🙂

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 April 2022 10:55 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/9 "2022-04-04T10:55:58Z")

</div>

Well, might not be what you want to hear but a 1 line function node becomes no-code once it has been written and put into a sub-flow.

As for the shelf - that's what you get when you diss people's languages 😀

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2022 10:58 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/10 "2022-04-04T10:58:51Z")

</div>

> [@cymplecy](#):
>
> are there any no-code alternatives using core nodes

core no - there is this 👇...

> [@Steve-Mcl](#):
>
> `node-red-contrib-buffer-parser` - it includes a "buffer maker" node.
> 
> ![chrome_plPSKCw54A](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab46765dd32a87f40c5ba651dd41f8a4a6d6ed4a.gif)

... and there is [protobuf](https://flows.nodered.org/search?term=protobuf&type=node)

and lastly there is this: a function node `msg.payload = Buffer.from(msg.payload)`😂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [27 May 2022 14:58 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/11 "2022-05-27T14:58:17Z")

</div>

I needed this again and I finally came up with a core node solution 🙂

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6cf98e1de07be14c15381adff74b9511ddf573c0.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/0/a0d5adfd8710ab4560fecd2fd9cdddfc674124f2.png)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 June 2022 14:58 UTC](https://discourse.nodered.org/t/convert-string-to-buffer/60755/12 "2022-06-10T14:58:51Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
