---
title: "Discussion on \"What REALLY happens when we require() a module in NodeJS?\" | Hashnode"
description: "Discussion on \"What REALLY happens when we require() a module in NodeJS?\". ## There are 5 steps in this process:\n- **Resolving & Loading**.\n- **Wrapping**.\n- **Execution**.\n- **Returning Exports**.\n- **Caching**.\n\n### **Step 1: Resolving & Loading**:\n> Before explaining this step, You should know that there are 3 types of m..."
url: "https://hashnode.com/posts/what-really-happens-when-we-require-a-module-in-nodejs/63a8f90a1ba9a9c0dc2a6927"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [What REALLY happens when we require() a module in NodeJS?](https://th3h4dyy.hashnode.dev/what-really-happens-when-we-require-a-module-in-nodejs?utm_source=hashnode&utm_medium=feed)

\## There are 5 steps in this process: - \*\*Resolving & Loading\*\*. - \*\*Wrapping\*\*. - \*\*Execution\*\*. - \*\*Returning Exports\*\*. - \*\*Caching\*\*. ### \*\*Step 1: Resolving & Loading\*\*: > Before explaining this step, You should know that there are 3 types of m...

Dec 26, 2022 · 2 min read · th3h4dyy.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#nodejs](https://hashnode.com/tag/nodejs)

## Written by

[Ahmed Elhady](https://hashnode.com/@th3h4dyy)

@th3h4dyy · Egypt

  
[View profile](https://hashnode.com/@th3h4dyy)

I'm Ahmed, A Software engineer who's focused on building and maintaining web applications.

I'm Ahmed, A Software engineer who's focused on building and maintaining web applications. I like to contribute to OSS and building tools to automate my workflow in my free time.

## Responses 1

Markdown supported · ⌘↵ to post

[Dean Tarisai](https://hashnode.com/@deantarisai)

[Dec 26, 2022](https://hashnode.com/posts/what-really-happens-when-we-require-a-module-in-nodejs/63a8f90a1ba9a9c0dc2a6927/comment/63a924878de4e0eeae64f01d)

Awesome post! But what causes an error to rise when I try to use an .mjs file inside of a js file ? Are they limits to interoperability of module formats ?

[Ahmed Elhady](https://hashnode.com/@th3h4dyy)

[Dec 26, 2022](https://hashnode.com/posts/what-really-happens-when-we-require-a-module-in-nodejs/63a8f90a1ba9a9c0dc2a6927/comment/63a924878de4e0eeae64f01d#reply-63a9800db1011ed9ec6d44cb)

Sometimes these problems rise because of some differences between `CJS` and `ESM` when it comes to use `.mjs` -- see the difference from here: [nodejs.org/docs/latest/api/esm.html](https://nodejs.org/docs/latest/api/esm.html#esm_differences_between_es_modules_and_commonjs)

People still shy from the `.mjs` and they use babel or typescript to get interoperability between the two types of modules.

I think it's the future, but, for now, they use the `.js` and allow for `ESM` in their code base in whatever method is available.
