How to Read Cosmosdb Data From Node.js

Using Node.js to Read Really, Actually Large Datasets & Files (Pt 1)

  • Write a program that will impress out the full number of lines in the file.
  • Find that the eighth cavalcade contains a person's name. Write a programme that loads in this data and creates an array with all name strings. Print out the 432nd and 43243rd names.
  • Notice that the 5th cavalcade contains a class of engagement. Count how many donations occurred in each month and print out the results.
  • Notice that the 8th column contains a person'southward name. Create an array with each start name. Place the nigh mutual commencement name in the data and how many times it occurs.

The 2 Original Node.js Solutions I Came Up With

Processing big 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 Solution I Chose to Run With & Why

Since my solution needed to involve such things as counting the full number of lines and parsing through each line to go donation names and dates, I chose to utilise the 2d method: fs.createReadStream(). So, I could use the rl.on('line',...) function to get the necessary data from each line of lawmaking as I streamed through the document.

Node.js CreateReadStream() & ReadFile() Code Implementation

Below is the code I came upwardly with using Node.js'south fs.createReadStream() part. I'll break information technology down beneath.

Initial Results from Node.js

With my working solution, I added the file path into readFileStream.js file for the 2.55GB monster file, and watched my Node server crash with a JavaScript heap out of retentivity error.

Fail. Whomp whomp…

The New Information Streaming Solution

I found my solution in the class of EventStream, a popular NPM module with over 2 one thousand thousand weekly downloads and a promise "to brand creating and working with streams easy".

EventStream Lawmaking Implementation

Here'due south my lawmaking new lawmaking using the NPM module EventStream.

Results from Node.js & EventStream: Circular 2

Ok, with the new solution implemented, I again, fired up Node.js with my two.55GB file and my fingers crossed this would work. Check out the results.

Woo hoo!

Determination

In the terminate, Node.js'south pure file and big data handling functions barbarous a little short of what I needed, only with just one extra NPM package, EventStream, I was able to parse through a massive dataset without crashing the Node server.

  • Postman vs. Insomnia: Comparing the API Testing Tools
  • How to Utilise Netflix's Eureka and Leap Cloud for Service Registry
  • Jib: Getting Adept Docker Results Without Any Noesis of Docker

hosmerpicamortiver1974.blogspot.com

Source: https://itnext.io/using-node-js-to-read-really-really-large-files-pt-1-d2057fe76b33

0 Response to "How to Read Cosmosdb Data From Node.js"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel