-: In the last section, we put
together all the source code that we're gonna need
for right now for the worker project.
Again, the worker is what's going to watch Redis.
Anytime that we get a new index inserted into Redis
the worker will automatically pull the value
out and calculate the appropriate fibonacci value for it
and then insert that value back into Redis.
We're now gonna start putting together the code
for the express server.
As a quick reminder, if you don't want to go through any
of this JavaScript specific setup, you can always move on
to the next section and you'll find all the source
code that we're writing inside that section.
So all you have to do is download the file there
and unzip it into your project.
I'm only walking you through all the source code right now
in case you're kind of curious
about how to write a JavaScript application that makes use
of all these different pieces.
So let's get started on the express server
that's going to serve as the sort
of API layer that communicates
with Redis and Postgres and communicates information
over to a running react application.
Back inside my code editor
we were just working inside that worker directory.
I'm now gonna make a second directory
that I'm going to call server.
And this thing is gonna house all the code for our server,
the express server, that's gonna function as the API.
Now, quick note here, please make sure
that you make the server directory next
to or as a sibling to the worker folder.
You do not want to place the folder inside
of the worker process. Don't want that.
So it needs to be outside in a separate sibling folder.
Now inside of here, we'll get started
by making a package.json on file.
We're gonna have a couple of different dependencies
and a couple of different scripts as well.
We'll first lift off or list off, excuse me
the different dependencies that our project is gonna have.
For dependencies, we're gonna get express at version
4.16.3.
We're going to get a Postgres client at 7.4.3.
We're going to get a Redis client at 2.8.0.
We'll get a Cores installation at 2.8.4.
And we'll get Nodemon as well for development purposes
at 1.18.3 like so.
And again, we'll talk about why we are installing Nodemon
as we start to put together the Docker side of this project.
Now next to the dependencies, I'm gonna also
define a script section.
Very similar to the worker process.
We're going to have a development script or a dev
script that runs Nodemon.
And then we will also have a start script
for node index.js.
All right, as usual, please double check
make sure that you've got your commas after each one
of these lines.
And make sure you've got double quotes everywhere inside
of here.
Need double quotes everywhere.
Once we've got the package.json file
all put together, I'll delete this, or excuse me
close the file, not delete it, my mistake.
And then inside the server directory
we're gonna make another file called keys.js.
And just like before this file is going to house some
of the different variables that we're going to
need to connect to the running instance
of Redis and the running instance
of Postgres that will be associated with our application.
Inside of the keys.js file
I'll say module.exports
and then inside of here, we're gonna have a pretty
good different number of pieces of configuration.
So please again, double check your typing in here
because we're gonna do a lot of typing.
I'll first do a Redis host that's gonna come
from the environment variable process.env.Redis host.
We'll get a Redis port.
We will get a PG user.
This is the Postgres user that we're going to log in as
from process.env.pg user.
We'll do a PG host.
We'll do a PG database.
This is going to be the name of the database inside
of Postgres that we're going to connect to.
PG database.
We'll get a PG password.
As you might guess, this is the password to the database
which we're going to have to define at some point.
So PG password.
We'll get a PG port.
Like so as well.
So we should see 1, 2, 3, 4, 5, 6, 7 entries inside of here.
Now I gotta ask you at this point again
please make sure that all of these environment
variable names are capitalized.
So you should see capital PG user, capital
PG host, capital PG database, and so on.
And also double check all the keys on the left
hand side as well.
You make a typo inside this file
it's gonna be a little bit of a pain to track
down in the future.
Please just do a quick double check inside of
here and make sure you've got the correct spelling
for stuff like say database on both sides and
the correct spelling for password on both sides and so on.
All right, so let's take a quick pause right here.
We're gonna come back the next section and
continue working on our server implementation.
I'll see you in just a moment.