Read CSV File using Node JS Mahesh K on August 09, 2018 I am currently working on a business project that exports the processed data to CSV file. I wanted to process that into the dashboard. I can choos... Read full post Submit Preview Dismiss Collapse Expand ItsASine (Kayla) ItsASine (Kayla) ItsASine (Kayla) Follow Azure DevOps and git admin with a weird interest in résumés and portfolios 🎉 Lawful Neutral Email dev@itsasine.dev Education Master's in Applied Mathematics Work DevOps | CI/CD | Release Engineer Joined Feb 4, 2017 • Aug 9 '18 • Edited on Jan 28 • Edited Dropdown menu Copy link Hide I just use fs. require('fs'); // ... readFile: function(path) { var fileContent; return new Promise(function(resolve) { fileContent = fs.readFileSync(path, {encoding: 'utf8'}); resolve(fileContent); }); } When I use the contents of the file, it's like stuff,stuff,stuff,stuff,stuff\r\n thing,thing,thing,thing,thing\r\n thing,thing,thing,thing,thing\r\n thing,thing,thing,thing,thing\r\n thing,thing,thing,thing,thing\r\n thing,thing,thing,thing,thing which is good enough for my purposes. Collapse Expand Ang3h Courage Ang3h Courage Ang3h Courage Follow Joined Jan 7, 2019 • Jan 7 '19 Dropdown menu Copy link Hide typo: fileContent = fs.readFileSync(path, {encoding: 'utf8'}); Collapse Expand ItsASine (Kayla) ItsASine (Kayla) ItsASine (Kayla) Follow Azure DevOps and git admin with a weird interest in résumés and portfolios 🎉 Lawful Neutral Email dev@itsasine.dev Education Master's in Applied Mathematics Work DevOps | CI/CD | Release Engineer Joined Feb 4, 2017 • Jan 28 '19 Dropdown menu Copy link Hide Fixed it now, thanks :) Collapse Expand Isa Levine Isa Levine Isa Levine Follow Isa (ee-suh). She/her pronouns. Full stack developer working with Java, React, Jenkins, and Kubernetes. Drinks too much bubbly water. Email isa.loves.coding@gmail.com Location Seattle, WA Education Masters in Education, Bachelors in English, Software Engineering at Flatiron Joined Mar 13, 2019 • Sep 1 '19 Dropdown menu Copy link Hide Hi Kayla, this is awesome! Do you mind if I link to this code snippet in a CSV-parsing dev.to article I'm working on? I'd love to include a purely fs solution. :) Collapse Expand ItsASine (Kayla) ItsASine (Kayla) ItsASine (Kayla) Follow Azure DevOps and git admin with a weird interest in résumés and portfolios 🎉 Lawful Neutral Email dev@itsasine.dev Education Master's in Applied Mathematics Work DevOps | CI/CD | Release Engineer Joined Feb 4, 2017 • Sep 1 '19 Dropdown menu Copy link Hide Go for it! :) Isa Levine Isa Levine Isa Levine Follow Isa (ee-suh). She/her pronouns. Full stack developer working with Java, React, Jenkins, and Kubernetes. Drinks too much bubbly water. Email isa.loves.coding@gmail.com Location Seattle, WA Education Masters in Education, Bachelors in English, Software Engineering at Flatiron Joined Mar 13, 2019 • Sep 2 '19 Dropdown menu Copy link Hide Thank you!! Here's the link to the article, with the link to your snippet in the conclusion. :) dev.to/isalevine/parsing-csv-files... Collapse Expand TahorSuiJuris TahorSuiJuris TahorSuiJuris Follow Joined Apr 12, 2019 • May 28 '19 Dropdown menu Copy link Hide Question, please: Why does this only return the first character of the string? const searchkeywords = fs.readFileSync('kwords.csv','utf-8'); for (let kword of searchkeywords) { console.log(`Search Keyword: ${kword}`); Text for the first 10 rows is: "1-800-FLOWERS.COM, INC.", "1ST SOURCE", "1ST SOURCE CORP", "3D SYSTEMS", "8X8, INC.", "A.H. BELO", "AAON", "AARON RENTS", "ABERCROMBIE & FITCH", "ABIOMED", Collapse Expand Brian Greig Brian Greig Brian Greig Follow Senior Engineer specializing in integration, data collection, data visualization, and data analytics. Family man and board game geek. Location Charlotte NC Education B.S. Computer Science - NYU. Currently completing M.S. in Computer Science at CCSU Pronouns he / him Work Senior Engineer Joined Nov 11, 2017 • Aug 13 '18 Dropdown menu Copy link Hide I generally prefer to use something like csvtojson and get it into a format that is easier to parse. Collapse Expand Steve Hsu Steve Hsu Steve Hsu Follow Location R.O.C Work Production manager at Vietnam Joined Sep 23, 2019 • Mar 2 '20 Dropdown menu Copy link Hide Thanks! It saved me. Collapse Expand Fabio Franchino Fabio Franchino Fabio Franchino Follow Coder, Designer, Dataviz(er) Location Italy Joined Jun 20, 2018 • Aug 10 '18 Dropdown menu Copy link Hide I wrote an article a while ago possibly related: fabiofranchino.com/blog/merging-cs... Collapse Expand Mahesh K Mahesh K Mahesh K Follow I write (about) code and keep interest in Data science, Venture Funding and startups. Joined May 2, 2018 • Aug 10 '18 Dropdown menu Copy link Hide This is handy for sure. Thanks a lot. Code of Conduct • Report abuse
I just use fs.
When I use the contents of the file, it's like
which is good enough for my purposes.
typo: fileContent = fs.readFileSync(path, {encoding: 'utf8'});
Fixed it now, thanks :)
Hi Kayla, this is awesome! Do you mind if I link to this code snippet in a CSV-parsing dev.to article I'm working on? I'd love to include a purely fs solution. :)
Go for it! :)
Thank you!! Here's the link to the article, with the link to your snippet in the conclusion. :)
dev.to/isalevine/parsing-csv-files...
Question, please:
Why does this only return the first character of the string?
Text for the first 10 rows is:
"1-800-FLOWERS.COM, INC.",
"1ST SOURCE",
"1ST SOURCE CORP",
"3D SYSTEMS",
"8X8, INC.",
"A.H. BELO",
"AAON",
"AARON RENTS",
"ABERCROMBIE & FITCH",
"ABIOMED",
I generally prefer to use something like csvtojson and get it into a format that is easier to parse.
Thanks! It saved me.
I wrote an article a while ago possibly related: fabiofranchino.com/blog/merging-cs...
This is handy for sure. Thanks a lot.