File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -92,8 +92,8 @@ Bugs Bunny,22
9292It could then be parsed, and results shown like so:
9393
9494``` js
95- import csv from ' csv-parser' ;
9695import fs from ' node:fs' ;
96+ import csv from ' csv-parser' ;
9797
9898const results = [];
9999
@@ -109,6 +109,27 @@ fs.createReadStream('data.csv')
109109 });
110110```
111111
112+ You can also use async iterators in modern Node.js versions:
113+
114+ ``` js
115+ import fs from ' node:fs' ;
116+ import csv from ' csv-parser' ;
117+
118+ async function readCSV (file ) {
119+ const results = [];
120+
121+ for await (const data of fs .createReadStream (file).pipe (csv ())) {
122+ results .push (data);
123+ }
124+
125+ return results;
126+ }
127+
128+ readCSV (' data.csv' )
129+ .then ((results ) => console .log (results))
130+ .catch ((err ) => console .error (err));
131+ ```
132+
112133To specify options for ` csv ` , pass an object argument to the function. For
113134example:
114135
You can’t perform that action at this time.
0 commit comments