DEV Community

Ajit Forger
Ajit Forger

Posted on

Understanding of CommonJS(Basics Node.js Series)

Image description

Hope you all are doing well,

In this micro article, we can understand what synchronous loading is, it's a basics concept of Node.js, which it's uses the Commons module systems.

So, before that, let's talk about CommonJs module systems.

CommonJS module systems

CommonJS modules are the module system for javascript programming language which is used in server-side and non-browser environments such as Node.js

CommonJs modules allow us to organize our code, make it reusable by its characteristics of encapsulation which is where we can make easier to manage and maintain large codebases.

Characteristics of CommonJs modules

Encapsulation

  • One of the key characteristics of CommonJs modules are it's encapsulation units
  • it's encapsulating the code and data, preventing them to interfere with other modules
  • This encapsulation is achieved by using of closures, which isolates the module scope

Exports and Require

Modules can export specific values, functions or objects so this way it can be available to other modules, by exports or module.exports object.

Synchronous Loading

CommonJS modules are loaded synchronously, to explain if a module required then, the entire modules and it's dependencies are loaded and executed before the program continues.

So, in this way programs executes by in order, order of execution

Conclusion

So, Thats its guys for now, Commons modules have more characteristics but for now we are cover some main characteristics, later we explore deep dive into their characteristics with examples to understand better.

Stay tuned for more advanced articles where we'll explore the depths of Node.js
If you have any queries or just want to share your Node.js anecdotes, and command below

happy coding! 🚀🐉💻

Top comments (0)