{"id":7562,"date":"2015-09-30T22:19:41","date_gmt":"2015-09-30T19:19:41","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=7562"},"modified":"2018-01-05T17:57:12","modified_gmt":"2018-01-05T15:57:12","slug":"node-js-modules-and-buffers","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/","title":{"rendered":"Node.js: Modules and Buffers"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-web-apps-with-node-js\">Building web apps with Node.js<\/a>.<\/p>\n<p>In this course, you will get introduced to Node.js. You will learn how to install, configure and run the server and how to load various modules.<\/p>\n<p>Additionally, you will build a sample application from scratch and also get your hands dirty with Node.js command line programming.<br \/>\nCheck it out <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-web-apps-with-node-js\">here<\/a>!<\/em><br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;7Yp6ijpjjxyeaN8A&#8217;]<\/p>\n<div class=\"toc\">\n<h4>Table Of Contents<\/h4>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#explanation_load&#038;export_module\">2. Load and Export Modules<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#load\">2.1. Load<\/a><\/dt>\n<dt><a href=\"#export\">2.2. Export<\/a><\/dt>\n<dl>\n <\/dd>\n<dt><a href=\"#buffer_operations\">3. Node.js Buffer Operations<\/a><\/dt>\n<dt><a href=\"#event_emitter\">4. Event Emitter in Node.js<\/a><\/dt>\n<dt><a href=\"#download\">5. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>To build structural applications adopting different patterns in different files, node.js provides us with the option for a module based system.<\/p>\n<p>In node.js, we add variables or functions to the object &#8216;module.exports&#8217;. By invoking the &#8216;require&#8217; function in a script which uses the module, will return the corresponding object (variables, functions etc &#8230;)<\/p>\n<ul>\n<li>For a module: module.exports points to an object.<\/li>\n<li>For a script: require(&#8220;module-filename&#8221;) returns that object.<\/li>\n<\/ul>\n<p>There are two types of node.js for the module interaction: <\/p>\n<p>1. When node.js does not have a relative hint about the file location.<\/p>\n<p>Example:<\/p>\n<p><code>var http = require('http');<\/code><\/p>\n<p>Here node.js looks for the core module named <code>http<\/code> and returns that module. This module should have been stored in the global repository space of our node.js application.<\/p>\n<p>Now, for the non-core modules, node.js will look into the folder structure and try to find out a folder name called <code>node_modules<\/code> and then find the module reference from that module. In other words, it will look for a required file named as per the required file reference with ajavascript extension (.js).<\/p>\n<p>2. Now when node.js works with a single file in some folder.<\/p>\n<p>Example:<\/p>\n<p><code>var http = require('.\/filename');<\/code><\/p>\n<p>Here node.js has the option to search for both filename.js and index.js &#8211; where the actual javascript file is referenced.<\/p>\n<h2><a name=\"explanation_load&#038;export_module\"><\/a>2. Load and Export Modules<\/h2>\n<p>In the node.js platform, there are requirements to have utility functions and common functions. But by default, all variables, functions, classes and member function of classes are accesible within a particular file only.<\/p>\n<p>Thus, some function declared within one file can not be accessed from another js file. As per definition, related node.js functionalities are described as modules. By default, when we write javascript functions within modules, they are accessed within that class and they are private to that module only, i.e. no other module or file can access these elements (variables, functions etc.). However, there are ways to expose those functions, variables or classes as needed.<\/p>\n<h3><a name=\"load\"><\/a>2.1. Load<\/h3>\n<p>In node.js, different external resources can be loaded in another module with the following syntax:<\/p>\n<pre class=\"brush:js\">\r\nvar checkData = require('.\/validatorutil');\r\n<\/pre>\n<p>Here, the &#8216;require&#8217; keyword is used to load an external module in the working module and the return type is assigned to a variable.<\/p>\n<h3><a name=\"export\"><\/a>2.2. Export<\/h3>\n<p>To expose functions and classes, we use module.exports and export those as per our requirements.<\/p>\n<p>In the function below, we have used the validator library of node.js.<\/p>\n<p><em><u>Check valid Email Address:<\/u><\/em><\/p>\n<pre class=\"brush:js\">\r\nvar checkEmail = function(value) {\r\n   try {\r\n      check(value).isEmail();\r\n   } catch (e) {\r\n      return e.message; \/\/Invalid integer\r\n   }\r\n   return value;\r\n};\r\n\r\nmodule.exports.checkEmail = checkEmail;\r\n<\/pre>\n<p>To use this in our required file we have written them as:<\/p>\n<pre class=\"brush:js\">\r\nvar checkData = require('.\/validation');\r\n\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkEmail(\"piyas.de@gmail.com\"));\r\n\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkEmail(\"piyas.de@gmailcom\")); \/\/ Return error\r\n<\/pre>\n<p>Some other useful functions that we can use for our daily tasks are:<\/p>\n<pre class=\"brush:js\">\r\n\/\/ Chcek minimum length\r\n\r\nvar checkMinLength = function(value,len) {\r\n\r\n   try {\r\n       check(value,'Please specify a minimum length of %1').len(len);\r\n   } catch (e) {\r\n       return e.message;\r\n   }\r\n   return value;\r\n\r\n};\r\n\r\n\/\/Check Maximum length\r\n\r\nvar checkMaxLength = function(value,lenmax) {\r\n   try {\r\n       check(value,'Please specify a maximum length of %2').len(0,lenmax);\r\n   } catch (e) {\r\n       return e.message;\r\n   }\r\n   return value;\r\n};\r\n\r\n\/\/Chcek boundary length\r\n\r\nvar checkBoundaryLength = function(value,lenmin, lenmax) {\r\n    try {\r\n         check(value,'The message needs to be between %1 and %2 characters long (you passed \"%0\")').len(lenmin,lenmax);\r\n\r\n    } catch (e) {\r\n         return e.message;\r\n    }\r\n    return value;\r\n};\r\n\r\n\/\/Check Numeric\r\n\r\nvar checkNumeric = function(value) {\r\n   try {\r\n      check(value).isNumeric();\r\n   } catch (e) {\r\n      return e.message; \r\n   }\r\n   return value;\r\n};\r\n\r\n\/\/Check AlphaNumeric\r\n\r\nvar checkAlphaNumeric = function(value) {\r\n   try {\r\n      check(value).isAlphanumeric();\r\n   } catch (e) {\r\n      return e.message; \r\n   }\r\n   return value;\r\n};\r\n\r\n\/\/Check LowerCase\r\n\r\nvar checkLowerCase = function(value) {\r\n   try {\r\n      check(value).isLowercase();\r\n   } catch (e) {\r\n      return e.message; \r\n   }\r\n   return value;\r\n};\r\n\r\n\/\/Check UpperCase\r\n\r\nvar checkUpperCase = function(value) {\r\n   try {\r\n      check(value).isUppercase();\r\n   } catch (e) {\r\n      return e.message; \r\n   }\r\n   return value;\r\n};\r\n\r\nmodule.exports.checkMinLength = checkMinLength;\r\nmodule.exports.checkMaxLength = checkMaxLength;\r\nmodule.exports.checkBoundaryLength = checkBoundaryLength;\r\nmodule.exports.checkNumeric = checkNumeric;\r\n\r\nmodule.exports.checkAlphaNumeric = checkAlphaNumeric;\r\nmodule.exports.checkLowerCase = checkLowerCase;\r\nmodule.exports.checkUpperCase = checkUpperCase;\r\n<\/pre>\n<p>And their use in the working file, respectively:<\/p>\n<pre class=\"brush:js\">\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkMinLength(\"abc\",2));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkMinLength(\"abc\",4)); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkMaxLength(\"abc\",2)); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkMaxLength(\"abc\",4));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkBoundaryLength(\"abc\",2,4));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkBoundaryLength(\"abc\",4,6)); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkNumeric(\"12\"));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkNumeric(\"ABC\")); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkAlphaNumeric(\"_!\")); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkAlphaNumeric(\"A23\"));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkLowerCase(\"lower\"));\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkLowerCase(\"Lower\")); \/\/ Return error\r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkUpperCase(\"UPPER\")); \r\nconsole.log(\"In testvalidation --&gt;\"+checkData.checkUpperCase(\"upPeR\")); \/\/ Return error\r\n<\/pre>\n<p>This is just the starting point to understand the load and export functionality in node.js.<\/p>\n<p>You may <a href=\"#download\">download<\/a> the associated Source code to mess around with.<\/p>\n<h2><a name=\"buffer_operations\"><\/a>3. Node.js Buffer Operations<\/h2>\n<p>Pure javascript is not efficient in handling binary data. For this reason, Node.js has a native layer implementation for handling binary data, which is a buffer implementation with the syntax of javascript. In node.js, we utilize buffers in all operations that read and write data. Thus, Node actually provides an interface for handling binary data in a quite efficient way. <\/p>\n<p>Some points to be noted for the node.js buffer implementation:<\/p>\n<ol>\n<li>A Buffer can not be resized.<\/li>\n<li>Raw data from the transport layer are stored in buffer instances.<\/li>\n<li>A Buffer corresponds to raw memory allocation outside the V8 javascript engine.<\/li>\n<\/ol>\n<p>Now let&#8217;s examine the syntax:<\/p>\n<ul>\n<li>To create a buffer for utf-8 encoded string by default:\n<pre class=\"brush:js\">\r\nvar buf = new Buffer('Hello Node.js...');\r\n<\/pre>\n<\/li>\n<li>To print the buffer, we can write:\n<pre class=\"brush:js\">\r\nconsole.log(buf);\r\n<\/pre>\n<\/li>\n<li>To print the text,as we have entered, we have to write:\n<pre class=\"brush:js\">\r\nconsole.log(buf.toString());\r\n<\/pre>\n<\/li>\n<li>To create a buffer of pre-allocated size, we write:\n<pre class=\"brush:js\">\r\nvar buf = new Buffer(256);\r\n<\/pre>\n<\/li>\n<li>Also we can store a value in each of the pre-allocated arrays with the following syntax:\n<pre class=\"brush:js\">\r\nbuf[10] = 108;\r\n<\/pre>\n<\/li>\n<li>We can assign encoding while creating the buffer or while printing it by using:\n<pre class=\"brush:js\">\r\nvar buf = new Buffer('Hello Node.js...','base64');\r\n<\/pre>\n<p>or <\/p>\n<pre class=\"brush:js\">\r\nconsole.log(buf.toString('base64'));\r\n<\/pre>\n<\/li>\n<li>A buffer can be sliced to small buffers with the following syntax:\n<pre class=\"brush:js\">\r\nvar buffer = new Buffer('this is a good place to start');\r\n\r\nvar slice = buffer.slice(10, 20);\r\n<\/pre>\n<p>Here the new buffer variable <code>slice<\/code> will be populated with &#8220;good place&#8221; which starts from 10th byte and ends with 20th byte of the old buffer.\n<\/li>\n<li>Also to copy from a buffer to another buffer variable we write:\n<pre class=\"brush:js\">\r\nvar buffer = new Buffer('this is a good place to start');\r\n\r\nvar slice = new Buffer(10);\r\n\r\nvar startTarget = 0,start = 10,end = 20;\r\n\r\nbuffer.copy(slice, startTarget, start, end);\r\n<\/pre>\n<p>Here the values will be copied from old buffer to new buffer.\n<\/li>\n<li>To copy the whole buffer with any value, we can use the &#8216;fill&#8217; method:\n<pre class=\"brush:js\">\r\nvar buffer = new Buffer(50);\r\n\r\nbuffer.fill(\"n\");\r\n<\/pre>\n<\/li>\n<li>buf.toJSON() returns a json representation of the Buffer object, identical to a json array.\n<pre class=\"brush:js\">\r\nvar buf = new Buffer('test');\r\n\r\nvar json = JSON.stringify(buf);\r\n\r\nconsole.log(json);\r\n<\/pre>\n<p>Here <code>json.stringify<\/code> is called implicitly to maintain the json representation.<\/li>\n<\/ul>\n<p>There is in-depth documentation for the Buffer class which can be found <a href=\"http:\/\/nodejs.org\/api\/buffer.html#buffer_class_buffer\" target=\"_blank\">here<\/a>.<\/p>\n<p>Buffer allows node.js developers to access data as it is in its internal representation (as per its memory allocation) and returns the number of bytes used in the particular case. On the contrary, String takes the encoding and returns the number of characters used in the data.<\/p>\n<p>While working with binary data, developers frequently need to access data that have no encoding \u2013 like the data in image files. Examples also include, reading an image file from a TCP connection or reading a file from the local disk etc.<\/p>\n<h2><a name=\"event_emitter\"><\/a>4. Event Emitter in Node.js<\/h2>\n<p>The Javascript classes which inherit from Event Emitter in Node.js, generally are a source of different event\/events collection in our apps. With those classes we can listen in the <code>.on()<\/code> function on the object for the event that was specified in the arguments and work accordingly with the callback function codes.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush:js\">\r\nvar str = '';\r\n\r\nsomeObject.on('dataReceived', function(data) {\r\n    dataReceived += data;\r\n  })\r\n .on('end', function() {\r\n    console.log('The data received: ' + data);\r\n  })\r\n<\/pre>\n<p>The on() function returns a reference to the object it is attached to and can chain n number of event listeners.<\/p>\n<p>Now if we have to emit events from a function we need to write the following code:<\/p>\n<pre class=\"brush:js\">\r\nvar util = require('util');\r\n<\/pre>\n<p>In order to have inheritance functionality with EventEmitter in Javascript, we have to inherite the particular class with:<\/p>\n<pre class=\"brush:js\">\r\nutil.inherits(myEventEmitterClass, EventEmitter); \r\n<\/pre>\n<p>Here the <code>myEventEmitterClass<\/code> will be the class which will inherit the EventEmitter functionality.<\/p>\n<p>And then the actual Event emiiting will happen in the following code:<\/p>\n<pre class=\"brush:js\">\r\nmyEventEmitterClass.prototype.emittedMethod = function() {\r\n\tconsole.log('before the emittedMethod');\r\n\tthis.emit('emittedevent');\r\n\tconsole.log('after the emittedMethod');\r\n}\r\n<\/pre>\n<p>So, while the myEventEmitterClass will be used in the system, the <code>emittedEvent<\/code> will be exposed like:<\/p>\n<pre class=\"brush:js\">\r\nsomeObject.on('emittedevent', function() {\r\n    console.log('The emittedevent is called');\r\n})\r\n<\/pre>\n<p>The above is a short introduction of the EventEmitter in node.js. Utilizing this functionality can be a little bit tricky to a new node.js programmer, but will remain useful in various application areas. <\/p>\n<h2><a name=\"download\"><\/a>5. Download the Source Code<\/h2>\n<p>This was a tutorial of Buffers and Modules in Node.js. You may download the source code of this tutorial: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/Node_TestValidation.zip\">Node_TestValidation.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how to install, configure and run the server and how to load various modules. Additionally, you will build a sample application from scratch and also get your hands dirty &hellip;<\/p>\n","protected":false},"author":18,"featured_media":924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-7562","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Node.js: Modules and Buffers - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\" \/>\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.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js: Modules and Buffers - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/phlocblogger\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-30T19:19:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-05T15:57:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Piyas De\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/phloxblog\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Piyas De\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\"},\"author\":{\"name\":\"Piyas De\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424\"},\"headline\":\"Node.js: Modules and Buffers\",\"datePublished\":\"2015-09-30T19:19:41+00:00\",\"dateModified\":\"2018-01-05T15:57:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\"},\"wordCount\":1165,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\",\"name\":\"Node.js: Modules and Buffers - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"datePublished\":\"2015-09-30T19:19:41+00:00\",\"dateModified\":\"2018-01-05T15:57:12+00:00\",\"description\":\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Node.js: Modules and Buffers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424\",\"name\":\"Piyas De\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g\",\"caption\":\"Piyas De\"},\"description\":\"Piyas is Sun Microsystems certified Enterprise Architect with 10+ years of professional IT experience in various areas such as Architecture Definition, Define Enterprise Application, Client-server\/e-business solutions.Currently he is engaged in providing solutions for digital asset management in media companies.He is also founder and main author of \\\"Technical Blogs (Blog about small technical Know hows)\\\"\",\"sameAs\":[\"http:\/\/www.phloxblog.in\",\"http:\/\/www.facebook.com\/phlocblogger\",\"http:\/\/in.linkedin.com\/in\/piyasde\",\"https:\/\/x.com\/https:\/\/twitter.com\/phloxblog\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/piyas-de\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js: Modules and Buffers - Web Code Geeks - 2026","description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","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.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/","og_locale":"en_US","og_type":"article","og_title":"Node.js: Modules and Buffers - Web Code Geeks - 2026","og_description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"http:\/\/www.facebook.com\/phlocblogger","article_published_time":"2015-09-30T19:19:41+00:00","article_modified_time":"2018-01-05T15:57:12+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Piyas De","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/phloxblog","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Piyas De","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/"},"author":{"name":"Piyas De","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424"},"headline":"Node.js: Modules and Buffers","datePublished":"2015-09-30T19:19:41+00:00","dateModified":"2018-01-05T15:57:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/"},"wordCount":1165,"commentCount":2,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/","name":"Node.js: Modules and Buffers - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","datePublished":"2015-09-30T19:19:41+00:00","dateModified":"2018-01-05T15:57:12+00:00","description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-modules-and-buffers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Node.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/"},{"@type":"ListItem","position":4,"name":"Node.js: Modules and Buffers"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424","name":"Piyas De","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g","caption":"Piyas De"},"description":"Piyas is Sun Microsystems certified Enterprise Architect with 10+ years of professional IT experience in various areas such as Architecture Definition, Define Enterprise Application, Client-server\/e-business solutions.Currently he is engaged in providing solutions for digital asset management in media companies.He is also founder and main author of \"Technical Blogs (Blog about small technical Know hows)\"","sameAs":["http:\/\/www.phloxblog.in","http:\/\/www.facebook.com\/phlocblogger","http:\/\/in.linkedin.com\/in\/piyasde","https:\/\/x.com\/https:\/\/twitter.com\/phloxblog"],"url":"https:\/\/www.webcodegeeks.com\/author\/piyas-de\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=7562"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7562\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=7562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=7562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=7562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}