- So what else do we have globally available
to us in Node.js?
Well, we have some references to the current file
and the current directory.
So let's replace this with a few console.log messages.
Remember, console.log is available to us globally
without having to import anything.
So we want to log the __dirname
and the __filename.
We also want to make sure
that we're in the right folder.
So we will make sure that we're navigated correctly,
typing cd, dragging that file directory over.
And then we're going to say node global.
So now this is going to point directly at the directory
where the file is located
and then directly at the file.
So notice that the filename variable
includes the entire path.
So also available to us globally
is the common.js module pattern.
So this is the pattern we're going to use
to import other code into our files.
One way that we can import these other modules
is we can use this function.
First things first, we're going to import it
and this typically happens at the top of the file.
So we're going to import the path module from Node.
Now, the path module is one of those core modules
that's part of Node.js but in order to use it,
we have to import it
for us to be able to use all of these functions.
So why might I want to use one of these functions?
Well, I want to pull out just global.js
from the file extension that we're getting
from the filename variable.
So the way that I can do that
is we can use another template string.
We'll say the file name is.
We will use the template string here.
And instead of just wrapping this around the filename,
what we actually want to say is path.basename.
And this is a function
that's going to take in that filename as an argument.
We also want to make sure to close this string.
So we're opening it up with a back tick
and closing it with a back tick.
So when I hit save there,
we should be able to run this again.
Node global and check it out,
we've plucked this from that string using this function.
Any time we need to do any parsing of path values,
we can use these functions.
So another thing that we can do
is let's take a look at what's else is available to us
as part of that global object.
To do so, we're going to use a for loop.
So we'll say let key in global
and then we'll console.log each one of these keys.
So what we're saying here essentially
is let's take a look at that global object
and specifically, let's look at all
of the keys that are part of that object.
So you want to hit Save again,
you want to run this again.
Remember, you can hit the up arrow to see all
of the previous commands that you've run.
And this is going to give you some information
about the global is available is here
as well as a bunch of timing functions.
So we're going to discuss some
of these other global elements
in the next couple lessons.