Commonly used dependencies in backend

Development Dec 24, 2020

As a general rule, any project that's using Node.js will need to have a package.json file. What is a package.json file?

At its simplest, a package.json file can be described as a manifest of your project that includes the packages and applications it depends on, information about its unique source control, and specific metadata like the project's name, description, and author.

The important aspect of a package.json is that it contains a collection of any given project's dependencies. These dependencies are the modules that the project relies on to function properly.

Dependencies are packages or libraries that our application depends on to function. They are pre-written code designed to be used and reused by developers.

When you run npm install from the root folder of a given module, it will install any modules listed in that dependencies hash.

We can search dependencies on google by your requirement. To search any package you can go to https://www.npmjs.com/package/package or https://www.npmjs.com/get-npm and search any dependency by name.

Command to install any dependencies

npm install --save name-of-dependency (Will install the dependency with latest version)

npm install --save-exact name-of-dependency (Will install dependency with fixed version i.e. without semver range operator)

npm install --save name-of-dependency@<version> (Will install dependency with specified version) 

Dependencies installed can be viewed in package.json file in dependencies object.

Following is the list of some of the most commonly used dependencies:

  1. dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.

    Create a .env file in the root directory of your project. Add environment-specific variables on new lines in the form of NAME=VALUE

    Usage
    As early as possible in your application, require and configure dotenv.
    require(‘dotenv’).config()

  2. express: Express is a fast, unopinionated minimalist web framework for Node.js
    Following are some of the core features of Express:
    A. Allows to set up middlewares to respond to HTTP Requests.
    B. Defines a routing table which is used to perform different actions based on HTTP Method and URL.
    C. Allows to dynamically render HTML Pages based on passing arguments to templates.

  3. cors: Cross-Origin Resource Sharing is a protocol that enables scripts running on a browser client to interact with resources from a different origin.
    Used for enabling CORS requests.
    Usage
    var express = require('express')
    var cors = require('cors')
    var app = express()

    app.use(cors())

  4. path: Provides a way of working with directories and file paths.
    There is no need to install it as it is part of the core node and can be used by simply requiring it.

  5. fs: It provides a lot of very useful functionalities to access and interact with the file system.
    There is no need to install it as it is part of the core node and can be used by simply requiring it.

  6. lodash: Lodash is a JS library which provides utility functions for common programming tasks. It uses a functional programming paradigm. It contains tools to simplify programming with string, numbers, arrays, functions and objects.

  7. moment: Library for parsing, validating, manipulating and formatting date

  8. bcrypt: Used for working with passwords. Makes it easier to hash and compare passwords in Node.

  9. jsonwebtoken: It defines a compact and self-contained way for securely transmitting information between parties as JSON objects. This information can be verified and trusted because it is digitally signed. It can be signed using a secret or a public/private key pair.

  10. request: Designed to be the simplest way possible to make http calls. Helps our application to integrate with other services.

  11. multer: It is a middleware for handling multipart/form-data which is primarily used for uploading files.

  12. socket.io: It enables real-time bidirectional event-based communication

  13. aws-sdk: Helps connecting to aws services like storing files on aws S3, downloading files from S3, etc.

Demo project reference:
https://gitlab.com/logicwind/training-sessions/backend/graphql/boilerplate/-/tree/dev

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.