In Simple Words, Node.js Modules are JavaScript files which contains different functionalities in each separate files. Modules are very useful to organise the code which makes debugging or future editing very easy. Node.js comes with various very useful Inbuilt modules which can be used for creating different functionalities.

Node.js Inbuilt Modules

Node.js inbuilt modules are lightweight and inbuilt with Node.js installations. You can use these Node.js Inbuilt Modules in your app without any installation.
Here is a list of the built-in modules of Node.js version 6.10.3:
assert :  Provides a set of assertion tests
buffer : To handle binary data
child_process : To run a child process
cluster : To split a single Node process into multiple processes
crypto : To handle OpenSSL cryptographic functions
dgram : Provides implementation of UDP datagram sockets
dns : To do DNS lookups and name resolution functions
events : To handle events
fs : To handle the file system
http : To make Node.js act as an HTTP server
https : To make Node.js act as an HTTPS server.
net : To create servers and clients
os : Provides information about the operation system
path : To handle file paths
querystring : To handle URL query strings
readline : To handle readable streams one line at the time
stream : To handle streaming data
string_decoder : To decode buffer objects into strings
timers : To execute a function after a given number of milliseconds
tls : To implement TLS and SSL protocols
tty : Provides classes used by a text terminal
url : To parse URL strings
util : To access utility functions
v8 : To access information about V8 (the JavaScript engine)
vm : To compile JavaScript code in a virtual machine
zlib : To compress or decompress files

How to include Node.js Module into the app:

We can include any of above module by using the require() function. for example:

var http = require('http');

We can include any of above module by this method we just need to change module name in place of http.

This is the full code to use http module to create http server

var http = require('http');

http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/html'});
   res.end('Hello World!');
}).listen(8080);

In Next Tutorial we will learn how to create custom module at Node.js

Pin It on Pinterest

Shares
Share This