NoSQL & Cloud Firestore

To create a new project

Initiate NPM on your current project

npm init -y

Notice that you have a new file in the file-tree: package.json:

image-20231005083247468

//package.json should have content like this
{
  "name": "firebase",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Install webpack in the project

In the Webstorm terminal

Notice that you have a new folder node_modules

image-20231005083616406

Enforce webpack on NPM BUILD

To accommedate webpacks build step (converting multiple javascript files into a single that can be deployed and run)

  1. Create a new directory in the project root called src

image-20231005085847638

  1. Create a javascript file in the srcfolder called index.js such as this:

image-20231005092609564

  1. Create a javascript file the project root called webpack.config.js

    image-20231005092737694

  2. Insert the following content in webpack.config.js:

  3. Change package.json to the following

Exercises

The following exercises does not require you to make any styling.

A simple display on an HTML page using an approach such as the following will do just fine:

Each exercise-part (a,b,c) should be contained in its own function.

Exercise 1

In the following dataset:

A) Display a list of names of cities that are not capitals.

B) Display a list of names of cities that are either in USA or China

C) Display the name of the city and the population of the country with the highest population.

D) Display the name of the country with most cities in the list

  • You might have to use javascript after querying the collection

E) Display a list of names of cities that are capitals with a population higher than 5.000.000

E) Write a basic input-field in the HTML page. When the user enters a city name in the field and clicks a button, the application will display an alert with "found" or "not found" if the user has inputted a city name in the database.

Exercise 2 (Advanced)

  • Create a new project

  • Insert the following data into a new collection

  • Create a web application such that:

    • A user can enter a product name in a text input field and click a button.

    • The amount of stock of the product will be displayed on the page (styling is not important)

    • The category of the product will be displayed

    • The brand will be displayed

    • If the product is not found - an alert will inform the user

Last updated