kenliner.blogg.se

Nodejs readline
Nodejs readline












nodejs readline

NODEJS READLINE CODE

Node.js CreateReadStream() & ReadFile() Code Implementationīelow is the code I came up with using Node.js’s fs.createReadStream() function. It seemed easier to me, than having to split apart the whole file once it was read in and run through the lines that way. Then, I could use the rl.on(‘line’.) function to get the necessary data from each line of code as I streamed through the document. Since my solution needed to involve such things as counting the total number of lines and parsing through each line to get donation names and dates, I chose to use the second method: fs.createReadStream().

nodejs readline

The most straightforward is fs.readFile() wherein, the whole file is read into memory and then acted upon once Node has read it, and the second option is fs.createReadStream(), which streams the data in (and out) similar to other languages like Python and Java. Processing large files is nothing new to JavaScript, in fact, in the core functionality of Node.js, there are a number of standard solutions for reading and writing to and from files. The Two Original Node.js Solutions I Came Up With So let’s talk about how I approached this. txt file that’s 2.55GB and a folder containing smaller pieces of that main file (which is what I used while testing my solutions before moving to the main file). When you unzip the folder, you should see one main. Identify the most common first name in the data and how many times it occurs. Notice that the 8th column contains a person’s name.Count how many donations occurred in each month and print out the results. Notice that the 5th column contains a form of date.Write a program that loads in this data and creates an array with all name strings. Write a program that will print out the total number of lines in the file.

nodejs readline

Here’s the 4 questions asked, and a link to the data set that the program was to parse through. Since I’ve not worked much with raw data, and I’m always up for a new challenge, I decided to tackle this with Node.js and see if I could complete the challenge myself, for the fun of it. It piqued my interest as the challenge involved reading through very large files of data from the Federal Elections Commission and displaying back specific data from those files. Last week, someone in one of my Slack channels, posted a coding challenge he’d received for a developer position with an insurance technology company. This blog post has an interesting inspiration point.














Nodejs readline