Let's go back over to our Ed, we're going to update our CLIA action function and make sure that we
correctly calculate this directory and the file name, even if a user puts in some kind of relative
path like this right here.
OK, so back inside my editor, I'm going to first begin by going up to the top of the file and I'm
going to import the path module from path.
Remember, this is a part of the node standard library.
There are a lot of functions inside that this path module that help us kind of calculate different paths
on a file system.
Then inside my action function, I'm going to zoom in just to make this easier to read, I'm going to
do a console log and it's going to do a quick console logger to just to make sure we can only calculate
the directory and the file names by themselves.
So inside of this first console log, we are going to write out half join.
We're going to join together, process dot c d.
Asked her name, I'm going to pass inside their file name.
Then as a second, councillor log.
I'm going to add in half dot based name, file name.
The first council log right here is how we are going to calculate that directory variable, this is
going to take a look at what folder we are currently in inside of our terminal.
So whenever a user runs that book, serve command process is going to return whatever directory the
user ran that command from.
Then Pattenden name is going to take a look.
At whatever file a user provided, if the user provided just a normal file name, like, let's say notebook
James, then we're going to get back an empty string.
But if a user provides a sort of relative path like this right here, then we're going to instead get
back.
Just just notes.
That's what this Durnan does, it gives us back just whatever folder is specified inside that string.
The second consolation is that we're going to use to find the actual file name.
So if a user gives us a relative path like this right here, base name will give us just the file name.
And if a user gives us just a notebook, just like so, base name will also give us just notebook.
James.
Without a doubt, the easiest way to understand what's going on with all these different functions is
to just run this code.
So let's do that right now and see what happens.
It's going to save this.
I'm going to flip back over to my terminal.
I'm again, inside of my directory, inside of our Seelie project, and I'll do a node.
Index dogs.
Serve and then for the hearth right here that we put in, we're not actually trying to look up any files
or folders on the file system so we can put in absolutely any string here that we want.
So we can imagine the inside of this directory, there is some kind of folder called maybe notes.
Again, we're not going to actually look up that folder so we can just try to print out these different
paths.
Nothing is actually getting accessed.
Then I'm going to imagine that maybe inside of this imaginary notes directory, there is a notebook
JS file.
It's going to run that and now I should see the absolute path.
To this imaginary notes directory, and this is definitely the correct path for me, so I'm inside of
a workspace folder.
That's where I place all the different coding projects I have on my machine.
I'm inside of a folder, which is where I'm putting all the code for this course as I'm writing it,
the proper directory, just another folder inside there.
And then here's our actual book project directory right here.
So Seelie Dist Notes.
So that is our directory.
That is where we are trying to save some kind of note or JavaScript file to.
And then we also quickly pulled off just the file name from this relative path, so I get back just
notebook's.
Now, a user can put in just about any kind of path in here, and it's always going to work as expected,
and in theory, we're not going to try to create some kind of file called notes notebooks, which is
what we really wanted to avoid in all scenarios.
OK, it looks pretty good.
So the last thing we're going to do is go back over to our Ed.
Rather than doing a control log about these, we're going to instead assign them to variables and then
pass or pass the result into our serve function.
The first I can remove, the first consolo called.
And then assign that to a variable that I will call Durch or for directory, and I'm going to pass that
in as the third argument like so.
Then I'm also going to assign or remove that second console function called in this case, because this
is a very short little function called right here, rather than assigning the result to another variable.
I'm just going to pass that in directly to our second argument.
I'm going to take the path based name.
But it and then put it in as that second argument.
And that should be it.
It's going to save that and then one last test, the back inside my terminal, I'm going to try running
that same command again.
We should see the correct control logs coming out of our local Clie application now.
So here's from our local Seelie app.
I see that we are trying to save and fetch cells from the notebook's file and that file is in this directory.
I should also be able to repeat something very similar, but without any kind of a relative directory
on it.
So if I do just notebook's I see notebook details and that file is inside of this directory.
All right.
That definitely looks good to me.
All right, so this is fantastic.
Let's take a pause right here and continue in just a moment.