# Count the messages

**URL:** <https://discourse.nodered.org/t/count-the-messages/47412>\
**Category:** General\
**Created:** [20 June 2021 21:31 UTC](https://discourse.nodered.org/t/count-the-messages/47412 "2021-06-20T21:31:01Z")\
**Posts on this page:** 1\
**Showing post:** 12

<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:** [21 June 2021 10:48 UTC](https://discourse.nodered.org/t/count-the-messages/47412/12 "2021-06-21T10:48:44Z")

</div>

> [@usmanEmder](#):
>
> How can I show the "count of payload" in dashboard?

One way could be to add a 2nd output...

![vBuG0Z3t1c](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13143fc6875200bbd4641dc8141d06eb08844ee2.gif)

```auto
[{"id":"226f9f18a6afc487","type":"function","z":"553814a2.1248ec","name":"","func":"\nlet msgCount = context.get(\"msgCount\") || 0;//get remembered count\nlet sendMessage = false;\nlet countMessage = \"\";\nif (msg.payload === 1) {\n msgCount++; //increment count\n}\n\ncountMessage = \"Count of payload 1: \" + msgCount;\n\nif (msgCount >= 16) {\n msgCount = 0;//reset counter\n sendMessage = true;//instruct code to send the msg\n msg.payload = \"1\"; //set payload to a string of \"1\" as you requested\n}\n\ncontext.set(\"msgCount\", msgCount); //remember count\nnode.status(countMessage);\nlet msgWithCount = { payload: countMessage };\n\nif(sendMessage) {\n return [msg, msgWithCount];\n} else {\n return [null, msgWithCount];\n}\n\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1760,"y":80,"wires":[["5999900b2df185a4"],["e6140c609f34d805"]]},{"id":"5999900b2df185a4","type":"debug","z":"553814a2.1248ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1930,"y":40,"wires":[]},{"id":"0f206903f17e01f9","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":1590,"y":60,"wires":[["226f9f18a6afc487"]]},{"id":"08c8d12fc86a3f32","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":1590,"y":100,"wires":[["226f9f18a6afc487"]]},{"id":"e6140c609f34d805","type":"debug","z":"553814a2.1248ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1930,"y":120,"wires":[]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/count-the-messages/47412)._
