Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

Mern Stack Uncategorized
mern stack developers

Guide to build Mern stack on Google Cloud Platform GKE-2022

n the digital era, most businesses and organisations host applications on the cloud to avail most of the benefits associated with cloud-native platforms. In the past few years, the demand for cloud platforms has increased, especially from the COVID-19 breakout as the workflow is never interrupted for any reason. Therefore, it is mandatory for developers and other software engineers to be aware of how to build apps on various platforms. Similarly, every mern stack developer should be aware of the process involved.

 

The Google cloud platform :

It is a suite of cloud computing services that run on the same infrastructure that is used by Google to run its end products. For a mern stack application, GKE(Google Kubernetes engine) is used as a managed GCP Kubernetes solution, which allows a mern stack developer to run containerized applications built by this technology on the cloud. The reason for using GKE is to help mern stack developers to build and deploy apps into the K8 cluster as microservices take responsibility for security, monitoring, maintenance, etc. This is very beneficial for businesses in various ways.

 

Instructions on how to build on GCP GKE:

It is a four-step process that is a bit complicated, especially for those mern stack developers who are new to this field. Even experienced developers can face difficulties, but they can take the help of consultants who are experienced with this technology. Before that, one has to be aware of prerequisites like Docker and Kubernetes and how to build web applications using this technology.

 

 

  • Accounts creation in GCP:

 

To begin this journey, you need to create a new project so that various accounts are created and linked, which is a basic but important one. Create a billing account by using your existing Google account or create a new account. Then link the account with the project created to avail the benefits of cloud services for the project. You can modify or close the account as per the requirements. One can choose a package that is best for their business.

Then the mern stack developer should check twice to confirm that all the APIs are enabled which are used to run the dataflow in GCP are. The process is simple and easy as step-by-step documentation is mentioned on the official website if you face any problems. Then download the latest version of Google SDK. After that, create a service account which allows the developer to run the mern stack web application from a local machine then it can invoke the GCP dataflow pipeline with the permissions required.Once the account is created you need to generate a key and download a set variable named Google_Application_Credentials.

 

Syntax:

export GOOGLE_APPLICATION_CREDENTIALS=”/Users/bhargavbachina/gcp-credentials/gcp-dataflow-service-account.json”

Then use the below command to login into your GCP account.

gcloud auth login.

 

 

  • Install gcloud CLI and Configure:

 

The next step is to install and configure the cloud CLI (Command Line Interface). To install gcloud CLI on a system, a mern stack developer can take the help of documentation from the official website of Google to avoid any mistakes during installation. Before you use the GCI tool, you need to initialise it. The Google SDK is a must to initialise it. The below commands help you to do this.

 

// initializing

gcloud init

 

// auth login

gcloud auth login

 

Once the command is executed, it is redirected to the login page of GCP where the developer enters the credentials to proceed further. After successful login, the developer has to type the below command to configure it.

gcloud config set project brain fuel-test (where brain fuel-test is the project name).

 

 

  • MongoDB Atlas set-up:

 

Once the project is set up, the mern stack developer has to set up the MongoDB Atlas database, which is a fully managed cloud database. Create an account using Gmail to proceed further. Then create clusters with the information displayed on the dashboard. But make sure you select GCP. Then click on the connect button to connect the cluster. Give the necessary details mentioned. The developer can choose one of three ways mentioned below.

  1. Connect with MongoShell.
  2. Connect your main stack application.
  3. Connect using MongoDB compass.

Once the cluster is created, the next step is to create the database, which is started by clicking the collections button displayed on the screen. Then click on the “add my data” button to give the appropriate details associated with the project. The database is created and you can insert data by using the insert command. The last step is to connect the database with MongoDB Compass.Use the below command:

mongodb+srv://admin123:admin123@brain-fuel-cluster.zpikr.mongodb.net/?retryWrites=true&w=majority (where admin123 are credentialed, brain-fuel-cluster is Database name).

 

 

  • Building Mern Stack for production:

 

There are many ways to build a mern stack for production which depends on the project and business requirements.

 

 

  • Manual Implementation

 

Command used to build is 

 

// change to UI directory

cd UI

 

// build the app

npm run build

 

After running this command all static and build assets of a project are built under \build.

 

 

  •  Using Webpack

 

To build using this method you need to install webpack by below command:

 

// install web pack

npm install -g webpack webpack-CLI

npm install webpack webpack-cli –save

 

Then you can build the project.

 

 

  • Packaging with gulp:

 

This is an automated way to build apps which is better. For that use the below command to install gulp and proceed further:

 

// install gulp globally

npm install gulp -g

// install as a dev dependency

npm install gulp gulp-zip fancy-log del webpack-stream –save-dev

 

One can build mern stack applications using Docker. The next step is to deploying the app on GCP GKE which will be explained in next post.

 

About Us:

BrainFuel is a one-stop solution for mern-stack development. Most businesses utilise the expertise of our experienced mern stack developers to use this technology successfully without any issues.

 

Author

admin

Leave a comment

Your email address will not be published. Required fields are marked *