NODEJS Read CSV

Source: Internet
Author: User

There's a demand today. csv file

I was going to use the xlsx bag I used.

But I couldn't find a way to read a CSV document. I'm not happy to test the code.

I used to see a nodejs document when I saw a line read the file, is this CSV file used exactly?

and toss it out for yourself. Write the code below

Fs.readdir ("CSV", (err,files) =>{
if (ERR)
{
Console.log ("Readdir error", err);
Return
}
Console.log (files);
Let i = 0, sql = "";
function Rdfile ()
{
if (i >= files.length)
{
Console.log ("End End End--------------------------------------------------");
Fs.writefile ("Plan.sql", SQL);
Return
}
Console.log ("ReadFile", Files[i]);
SQL + = "--" + files[i "+" \ n ";
Const RL = Readline.createinterface ({input:fs.createReadStream (' csv/' +files[i],{encoding: ' UCS2 '})});
Rl.on (' line ', (LN) =>{
Let Larr = Ln.split (");
}). On (' Close ', () =>{
Console.log ("End file");
i++;
Rdfile ();
});
}
Rdfile ();
});

I'm in the CSV directory, so the CSV file

Then each file is sequentially processed into SQL statements

My CSV file is UCS2 encoded at the beginning of no setup and garbled

Look for a bit on the net originally is direct support, I also want to use Iconv

This CSV file column is a non-generic comma separated by the TAB key

Original page http://www.web-jia.com/view.php?a=35


Cyclic writes of implemented files in node. js
PHP and Ajax create advanced RSS aggregators
JSP, ASP, and PHP security programming
HTML 5 Multi-media components (video usage)
HTML5 's past, present and future
node. js Speed-Up Guide (1)
Intel is still bullish on HTML5
Create snooker Table tennis Club with HTML 5 (1)
Using node. js to develop multiplayer HTML 5 games (1)
Accessing Properties and methods
Useful PHP Components and Tutorials 21 (1)

NODEJS Read CSV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.