- [Instructor] npm keeps a cache
of reinstalled modules, so that it doesn't
have to get them every time,
but that sometimes can lead to unexpected results,
and worse, to an app that doesn't work properly.
And the symptoms will be somewhat vague at first,
but in most cases when you try to install a module
that should be working properly, and it doesn't,
or a version of a module that doesn't work,
just try clearing your cache.
npm's official docs say,
sometimes npm's cache gets confused.
That is sometimes a reality that will lead
to hours of frustration.
Clearing your npm cache would always be part
of your troubleshooting steps
when working with modules, and really
not understanding what's happening.
Since npm5, the cache self-heals,
but again we're talking about a process
that is not foolproof, and you might need to force it.
So let me demonstrate a few commands
worth knowing to manage your cache.
So we're back into the S code here,
and the first command that you should know
is how to do npm cache verify.
And this command will basically give you
a report of the cache itself,
and verify that everything is good and healthy.
So, we have the information "cache verified and compressed"
in this folder here, then the content verified,
what has been verified, content garbage collected,
index entries, and so on, so forth.
But let's say, for example, you need to clear
this cache, you're feeling not really good about
some behaviors on your system with npm,
what you can do is npm cache clean,
and now you need to force it with dash, dash, force.
Otherwise, it's not going to work.
Before npm5, you could do npm cache clean
and it would clean it, but now because
it does it automatically for you,
you need to force it if you want to force it, like so.
With these simple commands, you'll be able
to find out if there are any issues with your cache,
and if so, you can force clear your cache,
and resolve the issues, if anything.