Node.js – Dependency Management

Node.js – Dependency Management

Dependency management is part of the core Node.js experience. In this post, we will learn the various patterns of dependency management and how Nodejs load dependencies. Node.js – Dependency Management.

Dependency management is part of the core Node.js experience. In this post, we will learn the various patterns of dependency management and how Nodejs load dependencies.

Introduction

An important concept in Node.js is that you want to know the way dependency management is handled. This dependency management is part of the core Node.js experience. In this post, we will learn the various patterns of dependency management and how Nodejs load dependencies.

So, we could write our application using a single js file for everything, but that’s not modular. Node.js makes it very simple to write modular code.

Before we dive into the details, the first question to answer, the module. What is it? And why should we care about it?

In simple terms, a module is a code, that we group together, for the purposes of sharing and reuse. Modules, therefore, allow us to break down complexity in our applications into small chunks. This can help with understanding the code right down to finding and fixing bugs. If you want to know more about JavaScript Module systems, you can check  this post.

Node uses a facility for requiring *certain behaviors. This is based on CommonJS. In short, to bring a JavaScript file, we use the keyword *require.

I am assuming that you already know some basics of Nodejs. You can also check my earlier post  Node.js – Introduction for some background information if you are new to Nodejs.

Setting Up the Application

Let’s start simple. I’ve created a directory for the project, used npm init to initialize it, and created two JavaScript files (app.js and appMsg.js). This is how to project looks like and we will use this as a starting point for the demos. Also, you can download the final code from the git repo link mentioned later in the post.

Created 2 JavaScript Files

javascript nodejs clean code

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.

7 Tips to Write Clean JavaScript Code

Who Else Wants to Write Clean JavaScript Code? In this Javascript tutorial, you'll see 7 Tips to Make Your Coworkers Fall in Love With Your Code.

19 Simple JavaScript Coding Standards to Keep Your Code Clean

JavaScript coding standards for improving the quality of your code.This is important due to JavaScript being a dynamic language so using == might give you unexpected results due to it allowing the type to be different.

Top 5 Tips for Making Your NodeJS code Easier to Read

In this article, we’ll look at 5 tips for making your NodeJS code easier to read and understand. How to Make Your Node.js Code Easier to Read