Angular Universal - techniques

This application is part of the Guide to the Angular Universal course available on newline.co

Prerequisites

To make this applicatin up and running you need to install the followings on your local machine:

To accomplish tasks during the workshop you need:

Apart of that you need to have a Free MongoDB Cloud account

MongoDB setup

Once you're done with installation of the prerequisites you need to set up MongoDB and adjust your project.

  1. Navigate to https://cloud.mongodb.com/user and sign in to your account

  2. Create a new clustiner (free shared is enough) in region that is closes to you: img

  3. When your cluster is ready, click the Connect button and follow the prompts in the Connect to Cluster panel to:

    1. Allow access from anywhere
    2. Create a MongoDB user: img
    3. In the Choose a connection method step, select Connect with the Mongo Shell. Follow directions for downloading, installing, and configuring the MongoDB Shell to run on your system.
    4. When you've configured the MongoDB Shell to run on your system, copy the supplied command-line instructions to a safe place.
  4. If you haven't done it yet - clone this repository

  5. Feed database with data with the following two commands:

mongoimport --uri mongodb+srv://<username>:<password>@<hostname>/<database_name> \
--collection products --file db/products.json
mongoimport --uri mongodb+srv://<username>:<password>@<hostname>/<database_name> \
--collection users --file db/users.json

ie:

mongoimport --uri mongodb+srv://username:password@cluster0.1gerr.mongodb.net/myFirstDatabase \
--collection products --file db/products.json

Connect application with MongoDB

Edit the api.ts file to point to your MongoDB:

const dbUrl =
  'mongodb+srv://<username>:<password>@cluster0.1gerr.mongodb.net/myFirstDatabase';
const dbClient = MongoClient.connect(dbUrl, {
  useUnifiedTopology: true,
}).then((connection) => connection.db('myFirstDatabase'));

Final check

At the very end, try to install, build and start the application:

npm install
npm run build
npm start

After navigating to the localhost:8080 you should see an Angular Application up and running.