Welcome back.
Should you use index dogs in your projects or should you not?
That is the question.
This is a controversial subject among no developers.
Some love it for its ability to simplify imports and make it easier to use complicated modules with
dozens of files.
And some developers will suggest that you always use the direct path to your module, not relying on
any special behavior and note through all my experiences working with Node.
I've generally learned to prefer not to use index dogs.
For most projects, it's good to understand.
In case you see it, but it might add some unexpected confusion.
If we look at the no documentation for how the requir function finds the module that you specified.
It's actually quite complicated.
We've already seen that there's different behavior for built in modules where you just pass in the name
of that module.
Vs. modules that we've written ourselves, which begin with the dot slash or dot dot slash.
And index that J.S. adds on to this logic, we can see that there is a section here for loading the
index.
It adds another special case to this already fairly long logic.
It might not seem like such a big deal, but it's actually one of Ryan Doll, the creator of Node,
one of his 10 regrets about no jobs.
Which he presented at this large JavaScript conference in two thousand and eighteen.
In his own words, it needlessly complicated the module loading system that we've been talking about
in this section.
Now, to be clear, Ryan, in this talk wasn't saying that no GST was a mistake.
It's more a reflection of what he might have done differently, looking back on the past 10 years at
the time.
In hindsight, one of those things was index dogs and the complex logic that we saw just a second ago
around how require loads modules.
The good news is that we don't have to use index dogs.
We can keep things really simple.
If you can avoid a few of these little missteps, which I'll make sure to point out to, you know,
it becomes this really, really amazing tool.
Now, it's not the end of the world.
If you use index dogs in your projects.
I've used it on a few and things turned out just great.
But it's one of those things that over time you learn to be careful with.
Because of the potential for this added confusion among developers.
I hope this can be helpful if you ever come across a debate about whether using index dogs is more helpful
or more harmful.
You can now reference reliable sources like Rain Dogs Talk and the no GST documentation over here,
which I'll link to you from this video to talk about index dogs and potentially the complexity that
it might add.
With this additional knowledge, we can take one step closer to being senior node developers with an
understanding for some of these little quirks in dogs.
All right.
I'll see you in the next one.