- [Instructor] In the last chapter,
we took a look at the objects
and functions that are globally available to you.
One of those functions that's globally available
to you is the require function.
So in that one, we looked at how to load the path module
by wrapping it in this require function.
The require function is what we use to load modules.
And for this chapter and in the next few chapters,
we'll focus on those modules
that you don't have to install with anything.
They're already installed locally
with your installation of Node.js.
So the path module's an example of one of those.
We can use it to isolate the file name
from a full path.
So we could say path.basename, use __filename.
This is one that we saw before.
Let's also make sure that you're in the correct folder.
I am not, so then we'll say node core.
And that will let us know core.js is the file that we're in.
We can also use it to help create path strings.
The path.join function can be used to join them together.
So check this out.
Here on line four,
we're going to create a variable called dirUploads.
And here we'll say path.join.
We'll use __dirnam.
We'll say www, files,
uploads.
So now if you console.log this dirUploads value,
we will see that this has created a path for us.
So 03_01/start/www/files/uploads.
So any strings that you pass in here
will be appended to the path.
There's also a utilities module.
So let's go ahead and pull this in.
We'll say const util equals require the util module.
Util has a log method as well.
So let's put this all underneath here.
We'll say util.log
and we'll say path.basename, __filename.
So now we'll run it again.
This will give us a little bit more information
about our filename,
things like our date and the time
that we're running it.
So here we're seeing the information logged to the console
with the timestamp
because the util.log function timestamps each log.
There is also a module called v8.
So we're going to require v8 here
and with this, we can get information
about how much memory our app is using.
So let's try util.log again.
We're going to say v8.getHeapStatistics.
We will run node core again.
You'll get a sense of how much memory your app
is currently using.
There are a handful of modules
that you can use out of the box with Node.js.
In the next couple of chapters,
we're going to focus on these modules in particular.