meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ixc2024:tech:backend:start [2024/05/23 10:46] – hibaa | ixc2024:tech:backend:start [2024/08/26 05:20] (current) – hibaa | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====Comprehensive Guide to Setting Up the Backend of the Application==== | + | ====BACKEND: How To==== |
- | {{ : | + | In today' |
- | ====Green Measuring tools for Backend Support==== | + | This guide includes the following key sections: |
- | {{ :ixc2024: | + | * [[ixc2024: |
+ | * [[ixc2024: | ||
+ | * [[ixc2024: | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
- | |||
- | |||
- | =======Comprehensive Guide to Setting Up the Backend of the Application======= | ||
- | {{: | ||
- | |||
- | ==== Objective ==== | ||
- | |||
- | The backend is the backbone of the application, | ||
- | |||
- | ==== Components of the Backend ==== | ||
- | |||
- | ^**Component** | ||
- | |API Service | ||
- | |Database | ||
- | |Authentication |Manages user registration, | ||
- | |Data Processing|Handles business logic, data validation, and processing. | ||
- | |Cloud Provider |Ensures scalability, | ||
- | |||
- | ==== Technology Stack ==== | ||
- | |||
- | The diagram below shows an overview of the cloud infrastructure. We will be using Google cloud and the two main services will be Google App Engine for deploying the web frontend and the API and Google Storage for handling data. Firebase will be used as the main database and GCS will be used for saving photos, pdfs, videos and other types of files. | ||
- | |||
- | {{: | ||
- | |||
- | == Cloud Provider (Google Cloud) == | ||
- | |||
- | We will be using Google Cloud because it has excellent machine learning and data analytics services, competitive pricing and a slightly easier learning curve than AWS and AZURE for beginners. | ||
- | |||
- | Google also offers $300 USD credits to use on any of their services for newly created accounts. It has been verified with Google support that this offer will still be valid in August, in Malaysia. | ||
- | |||
- | == API Frameworks == | ||
- | |||
- | In the table below, we provide a list of popular frameworks that can be used to build the API service. You are free to use any framework of your choice however we recommend using express.js (node.js) for its simplicity, speed, and extensive middleware options. Our tutorial will be focused on express.js. | ||
- | |||
- | ^**Framework** | ||
- | |Express.JS (Node.JS)|Lightweight, | ||
- | |Django (Python) | ||
- | |SpringBoot (Java) | ||
- | |||
- | == Authentication == | ||
- | |||
- | We will be using **Firebase** authentication. It is easy to implement and supports various authentication methods. The tutorial will show how to integrate Firebase Authentication into an Express.js backend. | ||
- | |||
- | ==== Tutorial ==== | ||
- | |||
- | == Google Cloud Account Set Up == | ||
- | |||
- | **Create a New Project** | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ==== Enable Required APIs ==== | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ==== Set Up Cloud Storage | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ==== Install GCP CLI ==== | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ==== Set-Up Service Account ==== | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ===== Create API Service ===== | ||
- | |||
- | ==== Install Node JS ==== | ||
- | |||
- | We recommend using NVM (Node Version Manager). It makes it easy for managing multiple Node.js versions on the same machine. It works across macOS, Linux, and Windows (with nvm-windows). | ||
- | |||
- | === Mac and Linux === | ||
- | |||
- | ^curl -o- https: | ||
- | |||
- | === Windows === | ||
- | |||
- | Step 1: Download **‘nvm-setup.zip’** from the [[https:// | ||
- | |||
- | Step 2: Extract the contents and run the nvm-setup.exe installer. | ||
- | |||
- | Step 3: Install Node.js: | ||
- | |||
- | ^nvm install latest\\ nvm use latest^ | ||
- | |||
- | === Verify Installation (for all machine types) === | ||
- | |||
- | ^node -v\\ npm -v^ | ||
- | |||
- | ==== Create Express.js NodeJS Backend ==== | ||
- | |||
- | === Initialize a new nodejs project === | ||
- | |||
- | Create a folder for your project - for this tutorial we will call it waste-backend and initialize a new node application. | ||
- | |||
- | ^mkdir waste-backend\\ cd waste-backend\\ npm init -y^ | ||
- | |||
- | === Install Initial Dependencies === | ||
- | |||
- | Install the basic dependencies to get started with your node js project | ||
- | |||
- | ^npm install express axios cors body-parser^ | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ===== Version Control ===== | ||
- | |||
- | ==== Using GitHub | ||
- | |||
- | === Create GItHub account or use an existing one. === | ||
- | |||
- | === Initialize Git in API Service === | ||
- | |||
- | ^git remote add origin https: | ||
- | |||
- | Please remember to replace **< | ||
- | |||
- | ===== Integrating Firebase Authentication WIth Our API Service ===== | ||
- | |||
- | ==== Install Firebase Admin SDK ==== | ||
- | |||
- | Install the firebase-admin plugin from npm | ||
- | |||
- | ^npm install firebase-admin^ | ||
- | |||
- | ==== Initialize Firebase Admin SDK ==== | ||
- | |||
- | Create a file named auth.js in your project’s root directory and enter the code below: | ||
- | |||
- | ^const admin = require(' | ||
- | |||
- | ==== Creating Express.js Server with Authentication Endpoints ==== | ||
- | |||
- | Create a file named index.js in your projects root directory and enter the code below: | ||
- | |||
- | ^const express = require(' | ||
- | |||
- | This will allow you to create endpoints that can be used by the frontend to send or access data. The following URLs can be used to access the different endpoints. | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ===== Deploying API Service to Google Cloud ===== | ||
- | |||
- | ==== Create app.yaml ==== | ||
- | |||
- | To deploy the app we need to create a configuration file in our project' | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ^# [START app_yaml]\\ \\ runtime: nodejs20\\ \\ service: node-express-api\\ \\ # [END app_yaml]^ | ||
- | |||
- | ==== Explanation of Configuration: | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | |||
- | ==== Deploy your App Locally ==== | ||
- | |||
- | Deploy your Node app by executing the command in root directory of your project | ||
- | |||
- | ^gcloud app deploy^ | ||
- | |||
- | ====== | ||
- | |||
- | ====== | ||
- | |||
- | ====== Additional Resources ====== | ||
- | |||
- | ^Title | ||
- | |How to deploy Node JS to Google Cloud |[[https:// | ||
- | |Google Cloud tutorial | ||
- | |Python FastAPI tutorial | ||
- | |Integrating cloud SQL into your Node JS app |[[https:// | ||
- | |Getting started with NodeJS, Google Cloud, Firebase and Cloud Storage|[[https:// | ||
- | |||
- | ====== Partners ====== | ||
- | |||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||