# Reading CSV and make a history

**URL:** <https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824>\
**Category:** General\
**Created:** [23 August 2022 19:17 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824 "2022-08-23T19:17:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subsony](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Subsony](https://discourse.nodered.org/u/Subsony)\
**Post date:** [23 August 2022 19:17 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/1 "2022-08-23T19:17:35Z")

</div>

Good evening lads,

finding and reading the right manuels to some topic is horrible. Even if you dont know how to declare it to google.

So, im tryin here, after google isnt giving me answers.

I can create and write a .csv file for my deployment sensor. It works fine. Now i wont to show me the 5 latest entries in a history table. Therefor i have to put them in an array. Is theire any option to do that? Reading the .csv and show me the five latest?

Thanks for all help.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [23 August 2022 19:34 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/2 "2022-08-23T19:34:19Z")

</div>

Hi ..

you can read the csv with the Read File node ( a msg per line)

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

use the Join node to make the individual msgs into a single array

Use JS to slice the last 5 elements from the array

**Test Flow :**

```auto
[{"id":"c28fc7517ecaa404","type":"file in","z":"54efb553244c241f","name":"","filename":"c:\\Share\\test.txt","filenameType":"str","format":"lines","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":380,"y":1760,"wires":[["922118e93d68597f"]]},{"id":"922118e93d68597f","type":"join","z":"54efb553244c241f","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":570,"y":1760,"wires":[["2b67c91d7f017942"]]},{"id":"b2e4905caef8626e","type":"debug","z":"54efb553244c241f","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":1760,"wires":[]},{"id":"6531d35ffed78268","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1760,"wires":[["c28fc7517ecaa404"]]},{"id":"2b67c91d7f017942","type":"function","z":"54efb553244c241f","name":"Slice 5","func":"msg.payload = msg.payload.slice(-5) // slice 5 last\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":1760,"wires":[["b2e4905caef8626e"]]}]

```

---

<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:** [23 August 2022 19:53 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/3 "2022-08-23T19:53:14Z")

</div>

However, if that is something you want to do you would probably be better using a database rather than a CSV file.

---

<div class="post-metadata">

**Author:** ![Subsony](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Subsony](https://discourse.nodered.org/u/Subsony)\
**Post date:** [23 August 2022 19:57 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/4 "2022-08-23T19:57:53Z")

</div>

Ah, nice. Thats the exact thing i looked for. Thanks alot.

---

<div class="post-metadata">

**Author:** ![Subsony](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Subsony](https://discourse.nodered.org/u/Subsony)\
**Post date:** [23 August 2022 19:58 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/5 "2022-08-23T19:58:30Z")

</div>

The Files arent that big, so i can store it in a .csv

---

<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:** [23 August 2022 20:16 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/6 "2022-08-23T20:16:43Z")

</div>

Just for info.  
You can do this just with the file in and csv nodes, both set to a single message array.  
You can select the entries required using the columns input field, and give the properties names.  
e.g.

```auto
[{"id":"6531d35ffed78268","type":"inject","z":"9a86d59e88442f2c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":350,"y":400,"wires":[["da28d0ba.59f458"]]},{"id":"da28d0ba.59f458","type":"template","z":"9a86d59e88442f2c","name":"simulate file in","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1,2,3,4,5,6,7,8,9,0\nq,w,e,r,t,y,u,i,o,p\na,s,d,f,g,h,j,k,l,z\nx,c,v,b,n,m,<,>,?,@\n","output":"str","x":290,"y":460,"wires":[["13d6da58.add826"]]},{"id":"13d6da58.add826","type":"csv","z":"9a86d59e88442f2c","name":"Select required using columns","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":",,,,,a,b,c,d,e","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":590,"y":460,"wires":[["b2e4905caef8626e"]]},{"id":"b2e4905caef8626e","type":"debug","z":"9a86d59e88442f2c","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":500,"wires":[]}]

```

---

<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:** [6 September 2022 20:16 UTC](https://discourse.nodered.org/t/reading-csv-and-make-a-history/66824/7 "2022-09-06T20:16:44Z")

</div>

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