We'll create the Angular app and add the Node and Express code to handle API routing.
- Install the Angular CLI
- Generate a new Angular app
- Install Express, and body parser.
- Create a new folder and file for
src/server/index.js
, add basic node/express logic - Create
src/server/routes.js
copy the routes in - Create a
/api/get
route (with hard coded heroes) - Create a
/api
route insrc/server/index.js
(link to routes.js) - Create a VS Code debug configuration for Node (Press debug, press configure, select Node.js, press green button)
- Change the launch config's launch program to our node server
- Press the green arrow to run the node server
- Open Postman and paste perform a GET http request on http://localhost:3000/api/heroes. You should see the following JSON results
- Add a component to list Heroes. The
--flat
flag adds the component without putting it in its own sub folder. - Copy this code into
heroes.component.html
- Copy this code into
heroes.component.ts
- Copy the styles.scss code
- Add the hero component's selector to the
app.component.ts
- Import Forms and Http modules into the app
- Create a model for our heroes,
hero.ts
- Add a service to handle http interactions between Angular and Node
- Copy the code into
hero.service.ts
- Build the app
- Create a VS Code debug configuration for Node, and press the green arrow to run it!
- Open the browser to http://localhost:3000
- Install the Azure CLI
- Login to Azure via the CLI
- Create a logical place for our Azure resources. This is a called a resource group.
- Create the Cosmos DB account and make sure it is of type MongoDB
- Check it out in the Portal
- Install the mongoose node package from npm
- Create
src/server/mongo.js
to handle mongo connections - Create the connection environment file
src/server/env/environment.js
- Enter the following Azure CLI commands to get the password and connection string. Copy these to your text editor, as we'll need them in a moment.
- Replace your port, database name, and password/key for Cosmos DB. You can find these in the Azure portal for your Cosmos DB account.
- Create the Hero model
src/server/hero.model.js
- Enter the following code to create the Hero model using a mongoose schema
- Create a service to handle heroes data using Mongo via Mongoose
src/server/hero.service.js
- Modify
src/server/routes.js
to use the newhero.service.js
- Restart the node process in the VS Code debugger.
- Open Postman and paste perform a GET http request on http://localhost:3000/api/heroes. You should see the following JSON results
- Open the app at http://localhost:3000. You should see the app no longer has any heroes, because we are hitting the new database.
- In the
src/server/hero.service
, create the post method and the helper functions. - In the
src/server/routes.js
, call the post function - Restart the node process in the VS Code debugger.
- Open the app at http://localhost:3000. Add a hero
- In the
src/server/hero.service
, create the post method and the helper functions. - In the
src/server/routes.js
, call the post function - Restart the node process in the VS Code debugger.
- Open the app at http://localhost:3000. Get, Add, Update, Delete !