Date: 30/09/2026
Iteration is the key to learning any skill, becoming an expert in it, or even becoming a master in it.
Yesterday, I was doing the second iteration of building a multi-user backend app, "My Contact," using the twelve-step intuition-based mental model. After finishing the learning, I found out that I did not completely understand exporting and importing techniques in Express.
Before starting to build the 2nd iteration, I really felt that I completely understood the full process of building a backend app with fully functional CRUD features.
I only realized it when I tried to build again completely on my own.
While exporting the router from the user route, I wrote:
module.exports = { router };
And was importing it as:
const router = require('./routes/userRoute');
Here, I got an error because I was using two different techniques of exporting and importing for the same variable.
I was exporting router wrapped inside an object, but while importing, I was importing it directly.
We cannot import directly a variable which is exported as a wrapped object. We have to use the object destructuring technique while importing it:
const { router } = require('./routes/userRoute');
How to import directly then?
We can import a variable directly only when we are exporting it directly.
For example:
module.exports = router;
Importing:
const router = require('./routes/userRoute');
This is the old technique of export and import in JavaScript.
The object wrapping and destructuring technique is a newer feature that was introduced in ES6. This is more useful when we need to export and import multiple variables from the same file.
While using the old technique of object import and export, we need to write more code, need to export each variable individually, and import each variable individually.
This learning is small, but very useful and powerful to become an efficient developer.
Multiple iterations are necessary to learn, improve, and become a master in any skill.
That's why:
Top comments (0)