{"id":83,"date":"2019-09-23T13:35:11","date_gmt":"2019-09-23T13:35:11","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/nodejs\/?p=83"},"modified":"2020-08-06T09:56:18","modified_gmt":"2020-08-06T09:56:18","slug":"node-js-streams","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/","title":{"rendered":"Node.js -Streams"},"content":{"rendered":"<p>We would cover Streams in Node.js under the following sub-topics:<\/p>\n<ol>\n<li><a href=\"#t1\">Introduction to Streams in Node.js<\/a><\/li>\n<li><a href=\"#t2\">Reading from Streams<\/a><\/li>\n<li><a href=\"#t3\">Writing to Streams<\/a><\/li>\n<li><a href=\"#t4\">Piping a Stream<\/a><\/li>\n<li><a href=\"#t5\">Chaining Streams<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong id=\"t1\">1. Introduction to Streams in Node.js<\/strong><\/p>\n<p>In Node.js, streams are used to read data from a source to a destination in a continuous manner. We would learn of four types of streams in Node.js. They are:<\/p>\n<ul>\n<li><b>Readable<\/b> \u2212 This is a stream\u00a0used for read operation.<\/li>\n<li><b>Writable<\/b>\u00a0\u2212 Stream which is used for write operation.<\/li>\n<li><b>Duplex<\/b> \u2212 This can be used for both read and write operations.<\/li>\n<li><b>Transform<\/b> \u2212 A type of duplex stream where the output is determined based on the input.<\/li>\n<\/ul>\n<p>Each of the type so streams listed above is an instance of EvenEmitter (<a href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/\" target=\"_blank\" rel=\"noopener noreferrer\">EventEmitters were discussed in Part 8<\/a>). They can fire several events at different times. For instance some of the most common events are:<\/p>\n<ul>\n<li><b>data<\/b> \u2212 This is fired whenever there is data is available to read.<\/li>\n<li><b>end<\/b> \u2212 This is fired whenever there is no more data to read.<\/li>\n<li><b>error<\/b> \u2212 This is fired whenever there is any error receiving or writing data.<\/li>\n<li><b>finish<\/b> \u2212 This is fired whenever all the data has been flushed to underlying system.<\/li>\n<\/ul>\n<p>Let&#8217;s now examine the operations you can perform with streams. We begin with reading.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t2\">2. Reading from a Stream<\/strong><\/p>\n<p>I have created a file named testinput.txt. The content is as follows:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Find all tutorial in kindsonthegenius.com\r\nAlso watch the video lessons.\r\n<\/pre>\n<p>Then, in VS Code, write and run the following program:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> data <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">''<\/span>;\r\n\r\n<span style=\"color: #888888;\">\/\/ Create a readable stream object<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> readStream <span style=\"color: #333333;\">=<\/span> fs.createReadStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Set the character encoding to be utf8. <\/span>\r\nreadStream.setEncoding(<span style=\"background-color: #fff0f0;\">'UTF8'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Handle stream data event<\/span>\r\nreadStream.on(<span style=\"background-color: #fff0f0;\">'data'<\/span>, <span style=\"color: #008800; font-weight: bold;\">function<\/span>(chunk) {\r\n   data <span style=\"color: #333333;\">+=<\/span> chunk;\r\n});\r\n\r\n<span style=\"color: #888888;\">\/\/ Handle the end event<\/span>\r\nreadStream.on(<span style=\"background-color: #fff0f0;\">'end'<\/span>,<span style=\"color: #008800; font-weight: bold;\">function<\/span>() {\r\n   console.log(data);\r\n});\r\n\r\n<span style=\"color: #888888;\">\/\/Handle the error event<\/span>\r\nreadStream.on(<span style=\"background-color: #fff0f0;\">'error'<\/span>, <span style=\"color: #008800; font-weight: bold;\">function<\/span>(err) {\r\n   console.log(err.stack);\r\n});\r\n\r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"End of Program\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In the program above we created and stream. Then we read from the stream.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t3\">3. Writing to a Stream<\/strong><\/p>\n<p>Now, we are going write to a stream. The code below create a writable stream. The it writes some text into it.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> data <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">'kindsonthegenius.com is the best place to learn'<\/span>;\r\n\r\n<span style=\"color: #888888;\">\/\/ Create a writable stream<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> writeStream <span style=\"color: #333333;\">=<\/span> fs.createWriteStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testoutput.txt'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Write the data to the stream with character encoding to be utf8<\/span>\r\nwriteStream.write(data,<span style=\"background-color: #fff0f0;\">'UTF8'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Indicate the end of file<\/span>\r\nwriteStream.end();\r\n\r\n<span style=\"color: #888888;\">\/\/ Handle stream finis event<\/span>\r\nwriteStream.on(<span style=\"background-color: #fff0f0;\">'finish'<\/span>, <span style=\"color: #008800; font-weight: bold;\">function<\/span>() {\r\n   console.log(<span style=\"background-color: #fff0f0;\">\"Data was written succesfully.\"<\/span>);\r\n});\r\n\r\n<span style=\"color: #888888;\">\/\/ Handle the Error event<\/span>\r\nwriteStream.on(<span style=\"background-color: #fff0f0;\">'error'<\/span>, <span style=\"color: #008800; font-weight: bold;\">function<\/span>(err) {\r\n   console.log(<span style=\"background-color: #fff0f0;\">'Error Occured: '<\/span> <span style=\"color: #333333;\">+<\/span> err.stack);\r\n});\r\n\r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"End of Program\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>This program creates the file specified. Then open it and writes into it. So run this code, then check the directory to see that a new file was created.<\/p>\n<p>Also introduce some error, just to make it fire the error event.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t4\">4. Piping a Stream to another Stream<\/strong><\/p>\n<p>Sometimes a pipe and a stream works together. You use a pipe to connect an output of a stream as input to another stream. This called piping. Now, you can pipe as many streams as you want. In the code below, we would read data from a readable stream and write it into another stream.<\/p>\n<p>In the code below, we create two streams: readStream and writeStream. Then we pipe the readStream into the writeStream.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/ Program to demonstrate Piping operation<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Create a readable stream object<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> readerStream <span style=\"color: #333333;\">=<\/span> fs.createReadStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Create a writable stream object<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> writerStream <span style=\"color: #333333;\">=<\/span> fs.createWriteStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testoutput.txt'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Pipe the readstream into the writeStream<\/span>\r\nreaderStream.pipe(writerStream);\r\n\r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"End of Program\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong id=\"t5\">5. Chaining Streams<\/strong><\/p>\n<p>Similar to piping, is another mechanism called chaining.<\/p>\n<p>Chaining allows you to connect the output of a stream to another stream. Therefore, you can chain multiple stream operations. Oftentimes, chaining is used along with piping.<\/p>\n<p>For example, we are going to use piping and chaining to first compress a file. Then we decompress the same file.<\/p>\n<p>&nbsp;<\/p>\n<p>The code is given below:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> zlib <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">'zlib'<\/span>); <span style=\"color: #888888;\">\/\/compression module<\/span>\r\n\r\n<span style=\"color: #888888;\">\/\/ Compress the file testinput.txt to testinput.txt.gz<\/span>\r\nfs.createReadStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt'<\/span>)\r\n   .pipe(zlib.createGzip())\r\n   .pipe(fs.createWriteStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt.gz'<\/span>));\r\n  \r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"File was Compressed.\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If you run the code above succefully, then it would compress the specified file. Now you can check the directory. You&#8217;ll notice that a compressed file has been created. The folder in my system is shown below.<\/p>\n<p><a href=\"https:\/\/kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-85\" src=\"https:\/\/kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node.jpg\" alt=\"Streams in Node.js\" width=\"581\" height=\"329\" srcset=\"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node.jpg 682w, https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-300x170.jpg 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now, we would run a code to decompress the same file. The code is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> zlib <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">'zlib'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Decompress the file testinput.txt.gz to testinput.txt<\/span>\r\nfs.createReadStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt.gz'<\/span>)\r\n   .pipe(zlib.createGunzip())\r\n   .pipe(fs.createWriteStream(<span style=\"background-color: #fff0f0;\">'D:\/nodefiles\/testinput.txt'<\/span>));\r\n  \r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"File was Decompressed.\"<\/span>);\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We would cover Streams in Node.js under the following sub-topics: Introduction to Streams in Node.js Reading from Streams Writing to Streams Piping a Stream Chaining &hellip; <\/p>\n","protected":false},"author":1,"featured_media":86,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js -Streams - Node.js Tutorials<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js -Streams - Node.js Tutorials\" \/>\n<meta property=\"og:description\" content=\"We would cover Streams in Node.js under the following sub-topics: Introduction to Streams in Node.js Reading from Streams Writing to Streams Piping a Stream Chaining &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/\" \/>\n<meta property=\"og:site_name\" content=\"Node.js Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-23T13:35:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-06T09:56:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"879\" \/>\n\t<meta property=\"og:image:height\" content=\"369\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Node.js -Streams\",\"datePublished\":\"2019-09-23T13:35:11+00:00\",\"dateModified\":\"2020-08-06T09:56:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/\"},\"wordCount\":529,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/Streams-in-Node-1.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/\",\"name\":\"Node.js -Streams - Node.js Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/Streams-in-Node-1.jpg\",\"datePublished\":\"2019-09-23T13:35:11+00:00\",\"dateModified\":\"2020-08-06T09:56:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/Streams-in-Node-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/Streams-in-Node-1.jpg\",\"width\":879,\"height\":369,\"caption\":\"Streams in Node.js\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-streams\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node.js -Streams\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\",\"name\":\"Node.js Tutorials\",\"description\":\"Best Node.js Tutorials\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js -Streams - Node.js Tutorials","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/","og_locale":"en_US","og_type":"article","og_title":"Node.js -Streams - Node.js Tutorials","og_description":"We would cover Streams in Node.js under the following sub-topics: Introduction to Streams in Node.js Reading from Streams Writing to Streams Piping a Stream Chaining &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/","og_site_name":"Node.js Tutorials","article_published_time":"2019-09-23T13:35:11+00:00","article_modified_time":"2020-08-06T09:56:18+00:00","og_image":[{"width":879,"height":369,"url":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Node.js -Streams","datePublished":"2019-09-23T13:35:11+00:00","dateModified":"2020-08-06T09:56:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/"},"wordCount":529,"commentCount":1,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/","name":"Node.js -Streams - Node.js Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg","datePublished":"2019-09-23T13:35:11+00:00","dateModified":"2020-08-06T09:56:18+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Streams-in-Node-1.jpg","width":879,"height":369,"caption":"Streams in Node.js"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-streams\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/nodejs\/"},{"@type":"ListItem","position":2,"name":"Node.js -Streams"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/","name":"Node.js Tutorials","description":"Best Node.js Tutorials","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/nodejs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/nodejs\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":123,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/83\/revisions\/123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/media\/86"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}