# Store txt content into a variable

**URL:** <https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792>\
**Category:** General\
**Created:** [17 March 2021 22:17 UTC](https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792 "2021-03-17T22:17:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![limpstar](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@limpstar](https://discourse.nodered.org/u/limpstar)\
**Post date:** [17 March 2021 22:17 UTC](https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792/1 "2021-03-17T22:17:17Z")

</div>

hey hello guys

I guess this is a trivial problem, but I just don't get it. I want to store a numbre from a txt file into a variable.  
I only have one number in the txt file. I want to store it into "count". The problem with my code is that he don't only stores the number, but also the additional info (see image). When I manually store a number into a variable, it works. See code below: Into "count" I store the payload from the txt file. Into "countertest" I store a number directly.

```auto
var counter = {payload: msg.payload};
var count=flow.get('count') || 0;
var countertest=flow.get('countertest') || 4;
flow.set('count', counter);
flow.set('countertest', countertest);
return counter;

```

![counter](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c3663db9197d4361f7bc16ae1e8d7cd3298258b.jpeg)

```auto
[{"id":"20ddb1cc.3f763e","type":"debug","z":"15c97f36.c1cd71","name":"get counter debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":240,"wires":[]}]

```

---

<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:** [17 March 2021 22:23 UTC](https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792/2 "2021-03-17T22:23:12Z")

</div>

> [@limpstar](#):
>
> `var counter = {payload: msg.payload};`

You are creating an object. Don't. Just put the value of msg.payload into the counter.

```auto
var counter = Number(msg.payload);

```

---

<div class="post-metadata">

**Author:** ![limpstar](https://avatars.discourse-cdn.com/v4/letter/l/71e660/32.png) [@limpstar](https://discourse.nodered.org/u/limpstar)\
**Post date:** [17 March 2021 22:30 UTC](https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792/3 "2021-03-17T22:30:11Z")

</div>

exactly what I was looking for, thank you so much :))

---

<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:** [31 March 2021 22:31 UTC](https://discourse.nodered.org/t/store-txt-content-into-a-variable/42792/4 "2021-03-31T22:31:13Z")

</div>

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