Set up the Node.js Express.js framework as a web API.
- [Instructor] Express is a minimal and flexible framework that allows us to easily create web apps and APIs to handle routing, requests, response, and implement custom middleware. Let's begin by creating a new folder for our backend inside our project. And now, let's open up this folder inside Visual Studio Code. Next, let's open up our terminal. So, I'll go over to view and then select integrated terminal. The next thing we need to do is initialize node.
So, let's use NPM init to create our package dot json file, which will allow us to specify any packages we install going forward. So, in the terminal, I'll type in NPM init. And I'll go with most of the defaults just by hitting enter. If we would like to make any modifications to those defaults in the future, we can always open our package dot json file and make the appropriate changes.
Inside here we can start to use Express, so let's bring it in with a require. And on the next line, let's create the Express app. The next thing I'd like to do is create a new generic route that tests that Express is working. We'll do that with app dot get, and pass in a slash for the routes location as the first parameter, and then we'll pass in an arrow function as the second parameter.
That takes in a request and a response. And then we'll send the response that simply says hello. Finally, let's start up our Express application by typing in app dot listen, and we'll pass in a port as the first parameter. And you can use any port number that's not in use. I've selected 1234. Let's save that, and then let's give it a try.
Inside our terminal, let's type in node, and then server dot js. If you do have a firewall enabled you can allow access to that. Now let's take a look at our test route by opening up our browser and going over to local host colon 1234. And as you can see, we're getting our hello response. Express is now set up, and we are ready to start working with our first real service.
- Setting up the infrastructure
- Displaying data in Angular 2
- Refining your layout with Angular Material
- Getting your data from Node.js
- Saving data to a list
- Creating the component
- Getting your input data
- Creating reactive forms in Angular
- Creating a security middleware
Skill Level Intermediate
Q: This course was updated on 10/17/2017. What changed?
A: We updated five videos to reflect changes to the setup and data retrieval and display processes in Angular 2. For example, instead of using a Git Angular template, the updated course uses the Angular CLI to generate a starting template, for a smooth runtime experience.