8.1 Setting Up The Server
Let’s have a quick tour of the server that we’ll be using for creating a persistent contacts app, using NodeJS and MongoDB with Express and Mongoose.
1.Introduction1 lesson, 01:02
2.All About Angular3 lessons, 15:49
3.Everyday Directives4 lessons, 30:00
4.Modules2 lessons, 08:35
5.Routing3 lessons, 18:30
6.Filters1 lesson, 06:20
7.Creating Directives2 lessons, 11:02
8.Talking To a Server5 lessons, 25:54
9.Conclusion1 lesson, 00:46
8.1 Setting Up The Server
In the next few videos, we're going to be using Angular to talk to a server using the NG resource module. But first I thought I'd take you through this server that I've built that will act sort of a back end for these videos. We may add some functionality halfway through the videos. But just to start with, I thought I'd show you around, so we can focus on Angular in the other videos. I'm using Node JS for the server, and Mongo is the database. We're gonna be building a Contacts App, and I've set up the contacts scheme here. You can see we're storing the name, first name, last name, and a clean version of the name that we're gonna use as an identifier. We're also saving an email, a potential telephone number, and the date that the contact was added. Before the contact gets saved, we are saving the clean version of them so that we always have that up to date. And if we haven't said when they were added, we're gonna add that too. I've also set the pervertual full name, which means it doesn't exist in the database, but we can use it in our App. And this is constituted of the first and last names. We can also set this name and I've set up here what happens when we do that. And it splits them up, and sets the first name, the last name, and the clean version. Down here, you can see the three API routes that I've got set up. The first one just gets all our contacts, so you can see it's using an empty query, with sorting by the last name, and then it returns all those to Angular. The next root is for getting a specific contact, and you can see that we pass the contact's name in the URL. This is used to query on the user's clean name. And this means we can have really nice URLs to see a contact's specific data, it would be /contact/Tom-Ashworth, for example, which is nicer than a long id. And when we get this back, we return it to Angular. Lastly, we can create a contact where you post to /api/contact. We will pass the name and as I've already said, Mongol will sort out turning this full name into the three ones that we actually want to store. We'll also store the email that's passed in the body and a number. And remember, we've got that post save hook up here that will add the Date in which the contact was added, which will be today's date, when the contact is added, or when the contact is saved, which happens down here, and then we return that contact to Angular. I've also set up a catch all route, which will redirect all requests to old URLs other than the API ones to the index.html file, which is where our angular app will live. This let's us use Angular's HTML 5 URL Support, which will give us some really nice looking URLs. So that was just a quick tour around the server that I'll be using in the next couple of videos. This code will be online for you to download and try out too.