# Replace() or tostring() "not a function"

**URL:** <https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040>\
**Category:** General\
**Created:** [24 July 2023 14:34 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040 "2023-07-24T14:34:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BitEater](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@BitEater](https://discourse.nodered.org/u/BitEater)\
**Post date:** [24 July 2023 14:34 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040/1 "2023-07-24T14:34:06Z")

</div>

I created a project with some flows on my Windows VM installation of Node Red. There is one function node with a line like

`msg.payload = msg.payload.replace("&amp;", "&");`

On my Windows VM it works fine. On my Raspberry Pi I get an error message saying "TypeError: replace() is not a function.". My Google search only gave the result to add "tostring()" before "replace()" but then I get "tostring() is not a function". Any ideas?

Thank you

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 July 2023 14:38 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040/2 "2023-07-24T14:38:48Z")

</div>

replace is a function of a string var, is msg.payload a string, add debug nodes and check what msg.payload is going into function  
`tostring()` should be `toString()` with a capital S.

---

<div class="post-metadata">

**Author:** ![BitEater](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@BitEater](https://discourse.nodered.org/u/BitEater)\
**Post date:** [24 July 2023 14:59 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040/3 "2023-07-24T14:59:47Z")

</div>

I am confused. I just restarted my Pi and now it works directly with replace()...  
Don't know why, but thank you for the hint. (Debug shows original payload is already a string)

---

<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:** [24 July 2023 15:37 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040/4 "2023-07-24T15:37:42Z")

</div>

> [@BitEater](#):
>
> Debug shows original payload is already a string

It wasn't a string the first time, or you would not have got that error.

---

<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:** [22 September 2023 15:38 UTC](https://discourse.nodered.org/t/replace-or-tostring-not-a-function/80040/5 "2023-09-22T15:38:20Z")

</div>

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