set of functions को ही modules कहते हैं। modules को आप JavaScript Libraries के जैसे समझ सकते हैं। जैसे libraries में functions define करते थे और उस file को add करके उन्हें use करते थे। same उसी तरह से NodeJS में modules को use करते हैं।

Node js में modules 3 तरह के होते हैं -

  1. Built In Modules

  2. Local / Custom Modules

  3. Third Party Modules

NodeJS Built In Modules

ये वो modules होते हैं , जो NodeJS के साथ predefined होते हैं। आप इन्हे directly use कर सकते हैं। कुछ important predefined modules इस प्रकार हैं।

ModuleDescription
assertProvides a set of assertion tests.
bufferTo handle binary data.
dnsTo do DNS lookups and name resolution functions.
eventsTo handle events.
fsTo handle the file system.
httpTo make Node.js act as an HTTP server.
httpsTo make Node.js act as an HTTPS server.
netTo create servers and clients.
osProvides information about the operation system.
pathTo handle file paths.
querystringTo handle URL query strings.
streamTo handle streaming data.
timersTo execute a function after a given number of milliseconds.
tlsTo implement TLS and SSL protocols.
urlTo parse URL strings.
vmTo compile JavaScript code in a virtual machine.
zlibTo compress or decompress files.

NodeJS Loading Core Modules

किसी भी module को use करने के लिए require('module-name') function का use किया जाता है , फिर हम उस module में defined functions / classes को need के according use कर सकते हैं।
For Example :

/*here we are going to add http*/
var http = require('http'); var server = http.createServer(function(req, res){ //write code here }); server.listen(5000);

ऊपर दिए गए example में http module को use किया गया है। इसी तरह से आप बाकी core modules को use कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers