NPM install CSV
Example CSV file You will need a CSV file for analysis, so either you already have it, or you can copy the text below and paste it into a new file and call this file "mycsv.csv".
ABC, 123, Fudge 532, CWE, ICECREAM 8023, POOP, DOGS 441, CHEESE, CARMEL 221, ABC, HOUSE 1 ABC, 123, Fudge 2 532, CWE, ICECREAM 3 8023, POOP, DOGS 4 441, CHEESE, CARMEL 5 221, ABC, HOUSE
Code reading example and parsing a CSV file
Create a new file and paste the following code into it. Be sure to read what happens behind the scenes.
var csv = require('csv');
Launch the application and check the functionality. Open the console and enter the following command:
Node app 1 Node app You should see the following output in your console:
[ MYCSV { Fieldone: 'ABC', Fieldtwo: '123', Fieldthree: 'Fudge' }, MYCSV { Fieldone: '532', Fieldtwo: 'CWE', Fieldthree: 'ICECREAM' }, MYCSV { Fieldone: '8023', Fieldtwo: 'POOP', Fieldthree: 'DOGS' }, MYCSV { Fieldone: '441', Fieldtwo: 'CHEESE', Fieldthree: 'CARMEL' }, MYCSV { Fieldone: '221', Fieldtwo: 'ABC', Fieldthree: 'HOUSE' }, ]
1 [MYCSV {Fieldone: 'ABC', Fieldtwo: '123', Fieldthree: 'Fudge'}, 2 MYCSV {Fieldone: '532', Fieldtwo: 'CWE', Fieldthree: 'ICECREAM'}, 3 MYCSV {Fieldone: '8023', Fieldtwo: 'POOP', Fieldthree: 'DOGS'}, 4 MYCSV {Fieldone: '441', Fieldtwo: 'CHEESE', Fieldthree: 'CARMEL'}, 5 MYCSV {Fieldone: '221', Fieldtwo: 'ABC', Fieldthree: 'HOUSE'},] Now you should open a web browser and go to your server. You should see how it outputs data in JSON format.
Conclusion Using node.js and its CSV module, we can quickly and easily read and use the data stored on the server, and make it available to the client upon request.