- [Instructor] Let's finalize our base server
by adding a few elements to our code
and then test it to make sure it works.
So the first thing I'm going to do
is add a start command inside our scripts
in the package.json file.
So if you don't have it open, click on package.json file
and then we're going
to reformat this particular script here.
So I'm going to first change test to start
and then inside of that command here,
I'm going to change a few things.
So this will allow us to start the server
and then run it with nodemon.
So let's go ahead and use nodemon.
And we're going to start with the index file
so that's the start file
which is right here
and I'm going to show you what is inside
of that project momentarily
so let's finish our code first.
So let's do index.js.
And we're going to execute it
with babel-node which will transpile
the latest version of JavaScript
into a readable code for the browser.
And then use the command -e
and look for js files.
Okay, so now we can save this.
So what I'm going to show you now
is what this project is made of.
So first of all, it's a Node and an Express server
that we are running with Mongoose
to connect to the database
and then we're using bodyparser to transpile the code
that's coming or the requests that are coming directly
from the browser
and then in the src file here,
you're going to see controllers
to execute the routes
and then the models.
So the controllers are the commands
that are going to execute the commands inside
of the database and the routes
are basically where we're going to execute those commands.
So this is mainly a base server
that we're going to use for security purposes.
Okay, so now that we've seen what's inside the code,
let's run it.
So I'm going to do npm start
and this is going to work because of what?
Because of the command that we just created inside
of our package.json file
and as I do npm start,
if the database is running in the background,
you should see this command without any errors.
If you're seeing any errors, it could happen
because frameworks are changing all the time.
If you see anything in here,
read the warnings, see if there's a fix for it
and most often than not,
you're going to have them fixed directly in the error message.
So if you see anything different here,
then read through the console messages and fix it.
So for example, in between the first version of this course
and this version, there was some errors around Mongo
which we fixed inside of the index here.
So we've actually added some piece of a code here
that allows us to use a NewUrlParser
and UnifiedTopology which is fairly new with Mongo.
All right, so now that we have our server running,
let's go to Postman.
And we're going to do a Get request.
So I'm going to do localhost.
Let's do 3000
and I'm going to go for contacts
which is basically the route
that will execute the controller
so if we go back to our code,
and look into the routes,
the contacts route
will run the controller in getContacts.
If we go into getContacts inside of the controllers,
it's going to get all the contacts
from the database.
All right, so let's go and run this in Postman.
I don't need to enter anything in the body
because this is a plain request
to get all the contacts.
I send it to the server
and right now, it's returning nothing
because there's nothing in this database.
Okay, so let's go ahead and add a new contact.
So if we go ahead and the first one is firstName.
Manny and if we want to make sure we can go back
to the model so if we go back to VS Code
and we take a look at the crmModel,
we can take a look at what it takes.
So firstName, lastName
so those two are required
and email, company, phone doesn't need to be there.
So we can really create a new contact
with just a few name and the last name.
So let's go back to Postman.
And we have the firstName entered.
And let's go to lastName.
Henri.
And now let's make sure we do a POST.
And let's go ahead and send it.
And now the database has created this brand new contact
inside of our database.
So now if we go back and do a Get again
to all the contacts,
we're going to get a list of all the contacts
inside of the database.
So right now we just have this one that we just created.
So everything is working as it should.
Now we're ready to secure this brand new project.
Let's move on.