Find your content:

Search form

Learn nodejs simple way - Nodejs Inbuilt modules?

 
Share

There is no need to reinvent everything from scratch because Nodejs provides list of builtin modules where we can utilize existing methods and apis wherever required. I have given few builtin node modules.

ModuleDescription
fsWhich is used to do the file handing operations i.e read, write, delete and etc...
osIt provides information about the operating system.
dnsUsed for DNS lookups and name resolution functions
cryptoIt provides the necessary methods for SSL cryptographic functions.
querystringIt is used to handle the query parameters.
urlIt is used to parse the URL
zlibIt is used to compress or decompress the files.v
v8It provides the information about the Google v8 engine.
http & httpsThese two modules used to create a server.
consoleThis module helps to write the data to the streams.

 

there are many more, you could visit https://nodejs.org/ website and take reference if needed. 

What is thirdparty modules and NPM (Node package manager)?

As a developer, you create a custom module which can be distributed to other developers in the world.

How it can be done? This can be done in few ways i.e you share your module code to developer through email, usb drive and etc... but how do other developers know about your work? (typically you have to advertise that have a module which is available for use).

It is a hard part to let others know about your work. To make easy the developers effort on advertising their module, "Isaac Z. Schlueter" developer came up with idea called NPM ( Node package manager) it is a centralized store where developers can share their module in this location and it will be visible to the entire world for the download.

 

How to use NPM?

NPM is a command line tool which can be used create or install the module from NPM repositories. Given few useful commands below.

npm init // which is used to create a new node module which asks few inputs i.e Project name, description, version and etc...
npm init --yes// which is used to create a project with default parameters
npm install <modulename> // Install other developer module into your project/module
npm install <modulename> --save-dev // This command install the module and it marked dev dependencies which means that it is not required for production environment.
npm install <modulename> -g // Install global which means this will be available for other projects as well.

 

What happens when you run npm init command?

Basically, it creates package.json file which contains the information about the project and its dependencies. Example given below.

{
    "name": "my_package",
    "description": "",
    "version": "1.0.0",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
    },
    "repository": {
      "type": "git",
      "url": "git url"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "bugs": {
      "url": "<url>"
    },
    "homepage": "<homepageurl>"
  }

 

 

 

 

 

My Block Status

My Block Content