00:02
So the first step here is to get our project
00:06
cloned down onto our machine
00:08
and then fulfill all of its prerequisites.
00:10
So on GitHub, I have the project
00:11
that we're going to be starting from
00:13
at a repository called Building with AdonisJS and Inertia.
00:16
The main branch of this repository
00:19
holds what we ended our Building with AdonisJS
00:21
and Inertia series with.
00:23
To get this project added onto our machine
00:25
rather than cloning it down
00:26
as we would a typical repository upon GitHub,
00:29
instead we're going to use this project as a starter kit
00:32
whenever we create our new AdonisJS project.
00:35
That's going to clone this repository down,
00:37
excluding all of the additional branches and commits
00:40
that were added as part of the
00:42
Building with AdonisJS and Inertia series.
00:43
So I'm gonna go ahead and assume
00:45
that you have Node.js installed on your machine.
00:48
You're gonna need at least version 20
00:49
in order to use AdonisJS.
00:51
If you don't, then you're gonna wanna head over
00:53
to nodejs.org and download it from here,
00:55
or you can use a Node version manager,
00:58
NVM or FNM, Fast Node Manager,
01:01
to get that installed on your machine.
01:03
Once you have Node installed,
01:04
we can jump into our terminal
01:06
at the location that we want to clone this project into,
01:08
and we can use npm init adonisjs @latest,
01:12
and then provide hyphen hyphen
01:14
to dig into the options hyphen capital K
01:17
to specify a starter kit.
01:19
And we'll point this to the
01:20
Adacasts/BuildingWithAdonisJS and Inertia.
01:25
Hit Enter to run that.
01:28
It's gonna ask where it should create this project,
01:30
and I'm gonna call this plotMyCourse_API
01:34
so that I can easily keep this code base separate
01:37
from the previous series.
01:38
You could just call this plotMyCourse or whatever you wish.
01:41
This is just gonna be the name
01:42
of the directory housing our project on our machine.
01:45
So we'll hit Enter there,
01:46
and it's gonna go ahead and get it downloaded,
01:48
install the packages.
01:49
Okay, cool.
01:50
So now the project is on our machine.
01:51
We can go ahead and CD into it.
01:52
It'll be at whatever that directory name is
01:55
that you provided above.
01:56
So I'm gonna CD into plotMyCourse_API
01:59
and clear our terminal out.
02:01
Now for my text editor,
02:02
I'm gonna be using Visual Studio Code.
02:03
So I'm gonna right-click this new window,
02:05
and let's go ahead and have that fill the screen there
02:08
and close that dialog out.
02:10
Okay, let's hit Open, and let's find our project.
02:13
So mine's at series,
02:15
and then plotMyCourse_API.
02:17
There we go.
02:18
And you might get some output warnings.
02:21
You can go ahead and close that dialog out.
02:22
We'll fill that out here next.
02:24
So let's dig into our .env.
02:26
You'll see that we have some empty variables here.
02:28
First, let's tackle the database.
02:30
So this is the DB prefixed environment variables
02:33
that we have here.
02:33
This project was set up to use Postgres.
02:35
That's the database driver that I'm using on this machine,
02:38
but it may not be the one that you're using on yours.
02:40
You could also be using SQLite, MySQL,
02:42
any of those that are supported by AdonisJS and Lucid.
02:44
So let's go ahead and clear those out of our .env file,
02:48
give that a save,
02:49
and then we can jump up to our config directory
02:51
where we should have a database configuration.
02:53
We can take a look at that momentarily.
02:55
It's just gonna look like this.
02:56
Let's delete this file.
02:57
So let's right click and delete, move to trash.
03:00
Let's go ahead and dive into our start directory
03:02
where we have our env.ts.
03:04
Those same environment variables
03:06
that we've cleared out of our .env file,
03:08
let's go ahead and clear that out of here as well.
03:10
Okay, one last adjustment.
03:11
Let's go ahead and dive into our package.json file
03:14
and scroll on down to our dependencies
03:17
where we should see PG added in here.
03:19
This is Postgres.
03:20
So we can go ahead and remove that line
03:22
as if you're not going to be using Postgres
03:24
as your database driver,
03:24
and you don't need the package installed in your project.
03:27
All right, next let's dive back into our terminal
03:29
and let's reconfigure Lucid.
03:31
So let's do node ace configure@adonisjs/lucid.
03:36
We already have Lucid installed within our package.json.
03:39
So here we just need to configure it.
03:41
So we'll run that.
03:43
It's gonna ask us which database driver we want to use.
03:45
Now, again, I'm using Postgres,
03:47
so that's what I'm going to select here,
03:49
but you feel free to select whichever one it is
03:51
that you'll be using.
03:52
All right, so I'm gonna select Postgres,
03:54
and then it's gonna ask me
03:55
if I want to install the additional packages,
03:57
and I'm gonna hit yes.
03:58
This is going to include that PG
04:00
that I just removed out of the package.json.
04:02
Cool, so we can see that it's created our config.database,
04:05
which we've just deleted.
04:06
It's updated our adonisrc.ts file,
04:08
updated our .env, updated our startenv.ts,
04:12
and then it's gone ahead and installed types luxen,
04:15
which was already in our package.json,
04:16
luxen itself, which was the same,
04:18
and then it re-added PG,
04:20
which we removed in the previous step.
04:22
Okay, we can clear this out,
04:23
dive back into our text editor,
04:25
where we should now see, okay,
04:26
looks like we have our db host port password,
04:29
so on, so forth, added back into here, so that's good.
04:32
Should now see it inside of our .env as well,
04:34
and this will set us up with some defaults
04:36
known to the database driver that we're using,
04:38
most notably the host and port there.
04:40
If we take a look at our config,
04:41
we have our database configuration back into there,
04:44
and then we didn't need to really worry
04:45
about the adonisrc.ts file,
04:47
as all that this really added
04:48
was within the service providers,
04:50
there will be, one of these will be
04:51
the database provider there,
04:53
and then another one will be Lucid,
04:54
those aren't driver specific,
04:56
those are Lucid specific,
04:58
so that's why we didn't clear anything
04:59
out of here originally.
05:01
Okay, so what we now need to do
05:02
is actually fill out the database environment variables.
05:04
Now, let's say that you don't have
05:06
a database driver installed on your system yet,
05:07
the easiest way to get one installed
05:09
is to use db-engine.
05:11
This is from the same people who made TablePlus,
05:14
this is actually what I use
05:15
to get Postgres installed on this machine,
05:17
all you need to do is download it for your platform,
05:19
and then you can select the service that you need,
05:21
and start or stop it,
05:22
as well as get it to launch on login to your system.
05:25
So that's a no fluff way
05:27
to get various database drivers there installed,
05:29
and then you can also use TablePlus
05:31
as a GUI interactor for your database.
05:34
And I actually have TablePlus already installed
05:36
on my machine, and I'm gonna go ahead
05:37
and open it up here,
05:38
and use it to get a new database set up for this project,
05:41
so that we all have the same starting point,
05:43
and I'm not working with pre-existing data
05:44
from the last series.
05:45
So with this open,
05:46
let's go ahead and hit create connection down here,
05:49
and select the database driver that you're using,
05:51
I'm using Postgres,
05:52
so I'm gonna select that, and hit create.
05:54
That's gonna open this dialog up,
05:56
and we are creating a new database,
05:58
so all that we wanna do is connect.
06:00
So just like AdonisJS,
06:01
this is going to pre-fill the host and port
06:02
based off of the driver that we've selected,
06:05
so all we need to do
06:05
is fill out the username and password.
06:07
So for me, that's gonna be Postgres,
06:09
and then password for the password.
06:11
We can hit test to make sure that that's A-okay,
06:14
and since everything highlighted in green,
06:15
that means that it is.
06:17
Again, we're gonna be creating a database here,
06:18
so I'm just gonna hit connect,
06:20
which will open this up,
06:21
and make a connection not specific to a database.
06:24
We can select this little database icon right up here
06:27
to open a database.
06:28
This will show a list of all of the ones
06:30
that you have at this connection.
06:31
We're gonna hit new to create a brand new one,
06:33
and I'm gonna call this plot my course underscore API.
06:37
Hit okay to create it,
06:38
and then we can go ahead and select it, and hit open.
06:40
Presently, it's empty,
06:42
but if we had tables in it,
06:43
those would be listed over here on the left-hand side,
06:45
down here at the bottom,
06:46
we can see the actual SQL that was executed,
06:48
which created our database.
06:49
All right, so we have our database created.
06:51
I'm gonna go ahead and close out of this,
06:52
and then that went ahead
06:53
and saved our connection right here.
06:55
I'm gonna go ahead and right-click this, edit it,
06:58
and make this specific to this database.
07:00
So I'm gonna drag this back up here.
07:02
Let's call this plot my course API,
07:05
and let's fill out the database name for the same.
07:08
So plot my course API, and hit save.
07:12
Okay, so now anytime that we want to inspect our database
07:14
within a GUI, all that we need to do is come into TablePlus,
07:17
and double-click this to open that connection
07:19
up to the specific database.
07:21
All right, we can go ahead and hide that away.
07:22
Let's hide our browser away as well,
07:24
and let's use those same connection details
07:26
to fill out our .env now.
07:28
So the host and port are okay,
07:30
as we're using the defaults there.
07:31
Let's fill out our username,
07:32
which is Postgres for me,
07:34
and then password for the password.
07:36
And then for the database name,
07:37
that is now plot my course underscore API.
07:41
Let's give that a save.
07:42
Next, we have our SMTP details.
07:45
For that, we're gonna use the same service
07:47
that we used in the last series, which is called MailTrap.
07:49
So I'm gonna head over to there,
07:50
and if you don't have an account, I already have one here,
07:53
but if you don't, you can go ahead and create a new one.
07:55
There's a free tier to this
07:56
that allows you to have one testing inbox.
07:58
Once you've registered and everything,
08:00
you should be presented with a screen like this.
08:02
We can go ahead and hit start testing
08:04
to dive into our inboxes.
08:05
Currently, we don't have any, so let's add an inbox.
08:08
We can give this a name of plot my course, and hit save.
08:12
All right, let's click on that inbox to dive into it,
08:15
where we should see our connection details.
08:17
We can simply click on one of those values
08:19
to copy it into our clipboard,
08:21
jump back into our text editor now.
08:23
That was the host that I copied,
08:24
so I'm gonna plop that into the SMTP host.
08:26
Then we need to get the port.
08:28
Any one of these should do.
08:29
I'm gonna do 2525, paste that in there.
08:31
And for this, we also need an SMTP username,
08:35
as well as an SMTP password
08:38
in order to fulfill this connection.
08:39
So let's grab those as well.
08:41
We'll grab the username there, plop that in there.
08:44
And then lastly, the password, and that goes right there.
08:48
All right, we can give that a save.
08:49
This project should already have the SMTP username
08:52
and password set up within the env.ts right there,
08:56
as well as in the config within the mail configuration
09:00
right here underneath auth.
09:01
So all of that is a-okay now.
09:03
All right, so one last .env that we need to add in
09:07
is app_url.
09:09
This is used within the emails
09:11
that are sent inside of this application.
09:13
And we just need to set this to host, import like so,
09:16
and we'll be good to go.
09:17
All right, now our .env is all set up,
09:19
so we should be able to jump back into our terminal here.
09:21
Before we boot our server up,
09:22
let's go ahead and do node.asemigrationrun
09:26
to get all of our tables created
09:28
inside of that brand new database that we set up.
09:30
All right, and then let's do node.asdbseed,
09:33
which just sets up our simple roles and initial seeder data.
09:37
All right, let's clear that out now.
09:39
And we should be able to npm run dev
09:41
to boot our application up.
09:42
And if all goes according to plan,
09:43
we should see our server URL right here,
09:46
which we can command click on
09:47
to open it up inside of our browser.
09:49
Okay, cool.
09:49
So now our application's all set up on our machine
09:51
and ready to go.
09:52
In the next lesson,
09:53
we will actually familiarize ourselves
09:54
with what we already have inside of this application,
09:57
and we'll go from there.
09:59
One last thing, mail trap.
10:01
We set up a test inbox within here.
10:03
So if we jump back into here real quick,
10:04
the way that this works, if you're unfamiliar,
10:07
is any emails that we send with this connection,
10:10
since this is a test inbox,
10:12
will only go to this inbox.
10:14
It won't actually send emails out
10:15
to whatever email it is that we enter in,
10:17
like a traditional SMTP connection would.
10:20
Instead, it's going to gobble all of those emails up
10:22
that we send with this application
10:24
and send them directly to this inbox here for us
10:27
to easily see, just to kind of be able to test
10:29
to make sure that everything's actually working
Join The Discussion! (0 Comments)
Please sign in or sign up for free to join in on the dicussion.
Be the first to Comment!