From the course: Angular: API Communication and Authentication

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Using Express Router

Using Express Router - Angular Tutorial

From the course: Angular: API Communication and Authentication

Start my 1-month free trial

Using Express Router

- [Instructor] Before we start adding authentication to our API, we need to do some small refactoring changes. While this is working, once we start adding more routes, the file will get get quite large. In addition, we have the database connection and variable that lives outside of the context where it is assigned, which is a bit of a code (mumbles). So let's clean things up. We first want to implement a function that takes in the database connection and returns the express app. In the server folder, create a new file called create-express-app.js. Require in express, and the bodyParser middleware. We will also need to bring in the path module. The function createExpressApp will take in a database connection. In this function, we create the express app. And then use a static middleware in the body parser middleware. We can actually head back to our index.js file. Copy and paste these lines. Next, we will tell express to use our API router for the API route. This function apiRouter will…

Contents