Skip to content

Third Party Packages

  • Thrid party modules is a module or package which is developed and manitained by 3rd parties.
  • Millions of 3rd party node modules/packages which are freely available on NPM Registry.
  • Node thrid party modules can be installed using NPM (Node Package Manager).

You can install thrid party package using command:

npm install module_name
        OR
npm i module_name

Packages Used

Third party package installed can be used by following way:

const variable_name = require('package_name');

Thrid Party Packages used are mentioned below:

Module Alias

Module Alias create aliases of directories and register custom module paths in NodeJS. It is configured in package.json file.

"_moduleAliases": {
    "@models": "./src/models",
    "@transformers": "./src/transformers",
    "@routes": "./src/routes",
    "@responseFormat": "./src/responseFormat",
    "@baseController": "./src/controllers/backend/baseController",
    "@baseService": "./src/services/base.service.js",
    "@services": "./src/services",
},

Axios

Axios is a very popular JavaScript framework used to perform network requests. It allows us to make both GET and POST requests which are the most used HTTP methods.

const axios = require("axios);

await axios({
    url: "users",
    method: "get",
});

axios.post(
    url: "users",
    method: "get",
    data: {
        // payload
    }
});

Bcrypt.js

Bcrypt.js This module enables storing of passwords as hashed passwords instead of plaintext.

const bcrypt = require("bcrypt);

// Generates hash password
bcrypt.hashSync(password, bcrypt.genSaltSync(10));

Dotenv

Dotenv Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env.

const dotenv = require("dotenv")
dotenv.config();

const connectUrl = process.env.DBCONFIG;

Cookie Parser is used to parse the cookies that are attached to the request made by the client to the server.

const cookieParser = require('cookie-parser');

app.use(cookieParser(process.env.COOKIE_SECRET, httponly: true, domain: 
process.env.DOMAIN}));

Body Parser

Body Parser parses an HTTP request body that usually helps when you need to know more than just the URL being hit. Specifically in the context of a POST, PATCH, or PUT HTTP request where the information you want is contained in the body.

Using body-parser allows you to access req from within routes and use that data.

const bodyParser = require('body-parser');

app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));

HTTP Status Codes

HTTP Status Codes indicate whether a specific HTTP request has been successfully completed.

const http = require("http-status-codes");

respondWithItem(res, data){
    return res.status(http.StatusCodes.OK).send(responseFormat(data));
}

Momentjs

Momentjs is a JavaScript date library for parsing, validating, manipulating, and formatting dates.

const  moment = require('moment');

// Add 1 day to current date and format it
moment().add(1, 'day').format("YYYY-MM-DD);