Node modules can be of three categories.
We have file-based Node modules where we define the Node module within a file,
within our application and we make use of it within our application.
Then, we have core modules that are already part of Node.
The Node designers kept these core modules intentionally small so
that Node can be kept small.
And also provide sufficient functionality so
that external module designers can add in their own
functionality that can be leveraged when we developed Node applications.
So the core modules include path, file system, os, util and a few others.
We will encounter some of them as we go along in this course.
Then we have external Node modules.
These are third-party Node modules that are developed by Node developers, and
then made available through the Node ecosystem.
So these external Node modules can be install within our system using NPM.
So many times you would see us using NPM install and
the name of the Node module and that will be included within
our Node application in a folder named node_modules folder.
And we will encounter external Node modules in a later lesson in this course.
How do we make use of Node modules?
When you need to use a Node module within another Node file within your application,
then you would use the require function.
I briefly mentioned about the require function in one of the previous
slides there.
The require function for file-based Node modules,
you will specify this as require and
then specify the path to the file which contains the Node module.
So you would say require./, the module name if the file exists
in the current folder written which your Node application exist.
So this specify the relative path to the file from the current location.
And also for the core and external modules,
you would normally specify them by saying require and the name of the module.
You would explicitly specify a path for it.
If it is a core module, it's already part of Node and so
it will be automatically included.
If it is an external module, then it will be installed either within
the node_modules folder in the current folder, or if the Node doesn't
find the external module within the node_modules folder in the current folder,
it will go up to the next higher level folder looking for that Node module.
Or the next higher level folder and
up the hierarchy until it locates the Node modules which will
then be imported to be used within your Node application.
If it is unable to find the Node module up the hierarchy,
then it'll obviously raise an error saying that the Node module is missing.
This way of organizing is very useful in the way
the Node application structure is defined as we will encounter