All right.
And once we have market data in the road, let's populate the database and we're going to do that first
will create populate jobs in the world very much right next through the mock data online, since it's
going to be a separate file.
So we're not going to run that inside of these server jobs.
We'll have to repeat some steps.
We'll have to connect to the database and remember our Connect DB function is looking for process,
not envy and then among all URL.
And therefore we'll need to import the data and repackage as well, just like we did in a server.
And then we'll also get the job and then we'll set up a star function just like we have in the server.
And remember this one, the popular address or on separately.
So basically, we'll stop our own server, the one that's spinning up right now, our application and
run, and we'll just invoke the popular address.
So a one time thing will just populate the database and then we'll move back to our project.
Now, as far as the functionality, like I said, we use Connect DB, so connect to a database run.
What's really nifty that on the model we have delete memory, which essentially is just going to clean
out our database.
And yes, it's going to remove all the jobs.
But in our case, we don't have that many anyway when we want to grab that JSON data.
And this is where it gets a bit tricky since we're using your six modules.
It's not as straightforward as with common.
If you have worked with common jazz where Jason, you know, but we simply need to import.
In this case, we do a little bit of acrobatics where we want to grab the reed file from the file system
module.
More specifically, the one that returns a promise.
Remember, by default, we get the callback one, but that's not what I want in years.
And then we want to go with Jason Pass.
Then we'll wait for Reed file when we need to pass in New York so that the file.
And then we need to have this import matter.
URL.
Again, this important matter you are, you'll see quite often when it comes to ES6 modules, because
again, some functionality is not as straightforward as with common dress.
Just keep that in mind.
And then once we have our JSON product, what are we can do with job create?
Instead of just passing in one job, we can pass in the array and then automatically all of those jobs
will be out of when we go with console.log success just so we know that everything works and we go with
process, exit and zero.
Now this is totally optional.
This is just to showcase that in node.
If you ever want to exit the program, meaning the process you can go with process, exit and then zero
means that everything went fine.
Basically, we're successfully exiting.
Or if there is an error which is going to be in the cache case, then we just log the error first and
we exit with the value of one.
So let's start cracking on that one.
And then let's go here, either route or go to populate.
And yes, Ron, first.
Let's grab the Reid file, I guess.
Import Reid File A. I know this is going to be for pretty much any duration that you want.
You have multiple approaches.
There's another one where you can convert the requirement.
But I thought that this one was a bit more straightforward.
We're going to go here with promises of that and we also want to grab the entry.
And I'm not going to repeat why we need that.
So we're going to go here with dot entry.
That's the package name.
Then remember, we need to set up our configured right away.
So config, let's invoke it.
And then let's grab two things the cannot be as well as the job models or import an ugly B will be my
name, and I just need to remember that I need to be viewed as one of the ways I'll get the error and
we'll do the same thing with a job.
So we're looking for the models and then job.
Yes, let's save it.
Let's set up that function.
So const start and it's going to be a sink.
And we're not going to pass anything in here and let's right away and just so we don't forget about
it.
And then when it comes to functionality, we want to go, try and catch because there's going to be
some synchronous actions.
First, let's connect to the database.
We're going to go with an ugly B.
And then let's pass in the process about the envy.
And then we're looking for Mongo and not underscore you, Earl.
That's the first step when technically this is optional, but I always like to also delete all of the
jobs.
Basically, I like to delete those items just so I can start from scratch.
And therefore, I'm going to go delete many and this will remove all of the jobs.
One.
Let's grab those JSON products so pranced name is really up to you.
But in my case, I'm going to go with products and that is equal to Jason.
Ron, let's pass it right away.
Pass.
And then let's pass in those values where I'm going to go with a weight, then read while.
So that's the functionality I'm importing here on the top.
And then let's pass in a few things.
First, we want to pass in that new URL and we need to say where the file is located.
So in our case, and that is going to be mark data, Andreas, and the second value is going to be import
matter.
And then, Dr. Earl, again, that's just the syntax that you need to use.
And once I have those JSON products, this is where I want to go with a weight job and then create and
like I said, what's really nifty that I can pass in my entire array and effectively I'll create those
jobs?
And not only that, I'll tie them right away to the John, let's say here success.
Just so we know that everything works and again optionally, we can go with process against it.
And I'm going to set it up as a zero.
Now let me copy this one just so I can speak up and instead of success, I want to see the error.
If there is wrong and also go with one hour of me double check, usually the file extensions are my
biggest issue.
And yep, right here.
It's not jazz.
It is actually Jason.
So let me save this one.
I want to stop my current server and we want to go with the node and you're going to passengers or you
can run node popular.
It doesn't really matter.
In this case, file extension is also optional.
And check it out.
We have success.
So now if I move to my database and take a look, are I should have 75 jobs.
So let me go here.
Let me refresh.
And if everything is correct, yep, I am seventy five total document.
So now and also we can do is to move back where everything.
And let's run AMPM Stark and what we should see in all jobs page, if you are logged in with that user,
of course you should see all of them.
So let me navigate to my current project for all jobs.
Now we're still searching because I mean, it's going to take a little bit to spin up the server and
everything.
But once everything is up and running, we should see all of those 75 jobs.
Yes, we'll set up the pagination and all of that is coming up, but we want to see the actual data.
And once we're done loading, What do you know?
I have all my 75 jobs and now we can start working on the stats page.