Our action function now has that file name and the port, these are two pieces of information that we
really want to communicate over to our local API because remember, the entire goal of that local API
is to serve up our react application number one, and then two other jobs are associated with it.
It needs to also save cells into a very particular file.
So that's the name of the file that was communicated to the Seelie.
And it needs to also fetch cells from that file as well.
So when a user runs this server, commands Arkley, we then need to take that file name and the port
and start up a local Express API.
So how are we going to communicate this information over to the local API when we start it up?
Well, we're going to use a very simple and straightforward approach.
From our local API package, we're going to export a function called serve this serve function is going
to be a function that starts up an express server.
The arguments to serve are going to be the part that we want to run our server on the name of the file
that we want to store cells inside of, and then the directory of that file as well.
That's what is right there.
Right now, our Seelie or the surf command really knows the port and knows the name of the file that
we want to store that list of cells inside of, and then we can definitely also figure out the directory
of that file as well.
So we need to import the search function that we're going to write out in just a little bit into our
Seelie, specifically into the search command.
We're then going to call that search function with a port, with a file name.
And with the directory of that file as well.
So then, like I said, inside the search function, we're going to start up our express server, we're
going to listen for traffic on that given port and then start to fetch and save cells into the given
file.
And that's pretty much it.
Now, just as a very quick aside here, I know that some of the stuff, particularly around the file
and how we're going to save cells and fetch cells from it might be just a little bit confusing.
I would recommend you not going to get too lost in that aspect.
Saving and loading cells from a file is going to be at the other day a lot more straightforward than
you might think.
So it just feels like to me that part is a little bit a little murky right now.
And if it is really don't sweat it, it's going to become crystal clear as soon as we start working
with it.
OK, so this is our general goal, so we need to go back over to our local API, we're going to create
a search function that's going to take these different arguments.
And then right now inside there, we'll just do a console log of those arguments.
We'll then import the search function over into our server command inside the Seelie and just try to
call it.
So just a very simple intermediate step right now.
All right, let's go back over to our Ed.
I'm going to find my local API package inside there is index.
Right now, we are exporting a function by default.
Let's instead export a named function, it's going to export bonds to serve.
Now it has just a very well defined name.
Well, then apply some different arguments and annotations to our SERP command, so this will be called
with a port that should be a no.
Remember right now inside of our Seelie, the port we receive is a string.
So we'll have to deal with that.
We need to get a file name that's a string and then a directory where that file exists, which we'll
abbreviate as Dir.
And that will be a string as well.
So then inside of our search function, again, for right now, we'll just do a console log and say.
Serving traffic on port and they'll point out the port.
I'll do another council log of.
Saving fetching cells from and I'll print out the file name.
And then finally, one last count log that just says something like that file is in directory Dir like
so.
All right, so let's say this will then go back over to our serve dots file, which is where a serve
command is written out.
So, again, inside of here, we're going to import that serve function we just put together and remember
that's inside of our local API package.
So to import it, we'll write out to import serve from and then the name of our local API package,
which is simply local Dasch API.
Then, rather than doing a simple console log right here, we will call surf.
We'll provide the port, which is going to come out of that options object, so we'll provide options.
Port.
Then file name.
And then a directory now we even really I said very briefly, oh, yeah, this directories where this
file exists, we haven't really gone into that and how we're going to determine what the directory is.
There's just a little gotcha around this.
I just want you to be aware of whenever you're taking in file names from users at a silly.
So right now I'm going to put in a directory of just forward slash like so and we'll come back to the
next video and do a deeper explanation of what that directory argument is all about and why we are communicating
it over.
Now, last thing I want to point out here is that options export the options argument right here is
technically typed as any.
So options export is also of type any is actually, of course, as we saw, a string.
So let's apply a manual type annotation to this options object.
Make sure we mark port as being a string, will then get an air coming from typescript saying, hey,
you're trying to provide a string when a number is required and that's where we will start to do it.
Just a little bit of no parsing.
So an options over here, I'm going to annotate this as an object that has a port property.
That is going to be a string.
So sure enough, we now get an air, we are told that we were providing a string when a number is expected
to fix that up once again, we just do a very simple pass on it.
We'll do a pass int.
And that should be it.
So once again, let's say this.
Go back over to our terminal.
And do another node index status, I'm going to run serv, I'm going to try to edit the books file and
I'm going to run everything on PT. five thousand and again, of course, remember, I'm running this
from the directory inside of my Seelie project.
I'm going to run that.
And there we go.
So we get a very correct council log here.
We're going to try to serve traffic report.
Five thousand cells are going to be fetched and loaded from the bookcase file.
And that file right now, again, just kind of a stand in right now.
OK, so this looks good now the entire point of this video was to really just show you how you're communicating
this information from our Seelie over to the local API.
And the reason I'm kind of making a really big deal about this is that very quickly, you're going to
start to realize that it kind of becomes a little bit kind of weird or murky.
What amount of logic we place into this action function versus logic do we place inside of our Express
API itself?
It turns out that there's like a lot of different arguments or a lot of different work, different things
we can calculate or figure out or stuff like that inside of our Seelie versus inside the Express package,
for example, this entire discussion that we're about to have in just a moment around this directory
argument, like I said, we need to provide or say, hey, here's the directory that the file that we're
trying to edit is in.
So at some point in time, we have to write out some code to figure out what directories the file name
is in.
And that, again, just very quickly becomes a question of, well, should we put the logic for that
inside of our CLI or inside of our local API package?
So, again, deciding what logic goes where just gets kind of a little bit weird.
And that's why I'm just kind of making a little bit a big deal around exactly what is being provided
from the Seelie over to the local API.
OK, so enough this with all this in mind, Quickparts are going to come back the next video and discuss
what the significance of this directory argument is right here and why we care about it at all.