Firebase configuration

This is an individual proces - you will all need a local development environment

Creating a development environment for Firebase

1. Initiate an empty project in webstorm

2. Ensure that the following applications are installed on your computer

Node

https://nodejs.org/en/download

NPM

What is NPMarrow-up-right

In the Webstorm terminal

npm install -g npm

In the Webstorm terminal

Verify that the packages are installed

node -v // It is installed if you see something like this (different version is fine): v18.9.1
npm -v // It is installed if you see something like this (different version is fine): 8.19.1

Initiate NPM on your current project

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

image-20231005083247468

Webpack

What is webpackarrow-up-right

To install Webpack:

In the Webstorm terminal

Notice that you have a new folder node_modules

image-20231005083616406

Node modules contain dependencies. Dependencies are external software packages we will use to develop software

We will use webpack, firebase and much more as dependencies to build an application

Building an application using webpack

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

Build the application with webpack

Run the following command in the terminal

If successful you should see an output like this:

Notice a new folder / file dist & main.js

image-20231005093431843

What just happened?

  • We configured the project using package.json and webpack.config.js to make npm and webpack work together

  • Basically we configured the project such that:

    • When the command npm run build is called

    • Webpack takes javascript from the index.js file and all relevant dependencies

    • And builds a new file containing all dependencies in main.js

Create 2 files in the dist folder: index.html & style.css

Copy the content from here:

https://github.com/nicklasdean/firebase/blob/main/dist/index.html

https://github.com/nicklasdean/firebase/blob/main/dist/style.css

  • When you run the HTML file it should look like this:

image-20231005100719918

Your project should look like this

Exercise 1

Expand the application such that:

  • When a user clicks the submit button - the users e-mail, name and password are logged to the console or displayed as an alert.

Notice: Now we can use the user-data in javascript

Building an application using Firebase: Cloud Firestore

Create a firebase project

Follow the following steps in this guidearrow-up-right

  • Create a firebase project

  • Register your app

  • Install firebase using NPM

Create a Cloud Firestore project

Follow the following steps in this guidearrow-up-right

  • Use Test mode

  • Select an EU location for the database

Use the configuration from Web modular API

Do not Prototype and test with Firebase Local Emulator Suite

You can find your configuration object in Project Settings:

image-20231005125856117

It should look something like this

Exercise 2

Follow the following guidearrow-up-right to verify if you can create / log data from Cloud Firestore

Initiate project

Inserting data (these lines of code should be deleted when you see data in the firebase console)

Fetching a single document

Fetching multiple documents

Exercise 3 (Advanced)

Create a collection in Cloud Firestore such as this:

image-20231005134821807

Expand your web-application such that instead of showing dummy data like this:

image-20231005134917487

  • The users from cloud firestore are displayed. Only their name, as email and password are sensitive information

Last updated