Node.js Tutorial – Component and Modules

We have seen the Nodejs Tutorial steps in the previous blog. Now lets understand the main and commonly used components and the modules in the Node.js and its usage in the Node.js application.

Node.js Components

Node.js uses the below given components:

  • Import required modules: Node.js application use the require directive to load the node.js modules

var http = require(“http”);  

  • Create Server: The server which listens to the node.js application request
  • Request & Response: The node.js server will intercept the requests from the browser / console and returns the response back to the client application.

Refer the below program which makes the use of these components

var http = require(‘http’);
var requestListener = function (req, res) {
res.writeHead(200);
res.end(‘Hello, World!’);
}

var server = http.createServer(requestListener);
server.listen(8080, function() { console.log(“Listening on port 8080”)})

Node.js modules

Node.js is built on JavaScript framework and creates .js files for processing. Node.js modules provides the functionality to add the encapsulation logic for segregating the functionality into different modules. Node.js provides the below available modules :

  • Express Framework: The provides the features to develop robust web and mobile applications
  • MongoDB: provides support for the MondoDB and Node.js integration for database operations
  • Restify: Framework to support REST APIs integration
  • Jade: provides high performance template engine for nodes and browsers
  • Bluebird: provides promise library with full of feature and performance enhancements
  • Socket.io: provides real -time bi-directional event based communication, mpostly use for developing chat application

Node.js build modules

Node.js provides the in-built modules for processing the java script application.

Module Name Module Description
assertProvides a set of assertion tests
bufferhandles binary data
child_processfor running the child processes
clustermanages multiple node processing
cryptomanages OpenSSL cryptographic functions
dgrammanages UDP datagram sockets
dnsmanages DNS Lookup and name resolution functions
domaindeprecated now.
eventsmanages events
fsmanages file system
httpmanages node.js to run as HTTP Server
https manages node.js to run as HTTPS Server
nethelps in creating server & clients
osprovides operating system data
pathmanages file path
punycodedeprecated now
querystringmanages URL query strings
readlinemanages readable streams one line at the time
streammanages streaming data
string_decoderdecodes buffer objects to strings
timersexecute a function after a given number of milliseconds
tlsmanages TLS and SSL protocols
ttyProvides classes used by a text terminal
urlparse URL strings
utilprovides utility functions
v8accesses information about V8 (the JavaScript engine)
vmcompiles JavaScript code in a virtual machine
zlibcompress or decompress files
Node.js Tutorial – Component and Modules
Scroll to top
Copy Protected by Chetan's WP-Copyprotect.