Home  >  Article  >  Web Front-end  >  How to process CSV files using Node.js

How to process CSV files using Node.js

不言
不言Original
2019-01-03 14:20:526761browse

Node.js is a server-side environment that can be run using JavaScript. CSV is text data, using commas as a column separator and newline code as a record separator. It is a format used for general use of Excel data in other applications. This article will introduce to you how Node.js processes CSV files.

How to process CSV files using Node.js

#How to use npm’s csv package?

In order to process CSV in Node.js, there is a way to use the npm csv module.

The actual use of the npm csv module is to convert JSON data and csv and read and write csv data.

How to install npm CSV module?

Command: Use npm install csv to install the csv module.

npm install csv

Concrete example of Node.js processing CSV files

How to use npm csv to convert Json data to csv

The code is as follows

const csv = require('csv')
const input = [ [ "1", "2", "3", "4" ], [ "php中文网", "在线编程", "短期掌握", "线上学习" ] ];
csv.stringify(input, function(output){
  console.log(output);
});

Display results

[ '1', '2', '3', '4' ],
[ "php中文网", "在线编程", "短期掌握", "线上学习" ]

Summary, the above is the entire content of this article. For more exciting content, you can pay attention to other related tutorial columns on the PHP Chinese website! ! !

The above is the detailed content of How to process CSV files using Node.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn