<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: John Dean</title>
    <description>The latest articles on Forem by John Dean (@captemulation).</description>
    <link>https://forem.com/captemulation</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F228078%2F4fdcbbeb-050d-4748-8747-3e234f4d6725.jpeg</url>
      <title>Forem: John Dean</title>
      <link>https://forem.com/captemulation</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/captemulation"/>
    <language>en</language>
    <item>
      <title>How to Deploy ML models with Google Cloud Run</title>
      <dc:creator>John Dean</dc:creator>
      <pubDate>Tue, 08 Dec 2020 19:26:08 +0000</pubDate>
      <link>https://forem.com/captemulation/how-to-deploy-ml-models-with-google-cloud-run-3fpn</link>
      <guid>https://forem.com/captemulation/how-to-deploy-ml-models-with-google-cloud-run-3fpn</guid>
      <description>&lt;p&gt;This blog post is part of our series on Serverless Inference for Machine Learning models accompanying our KubeCon 2020 talk: Serverless for ML Inference on Kubernetes: Panacea or Folly? - Manasi Vartak, Verta Inc. We'll be hosting a live replay on December 2nd at 2 PM ET for anyone who missed it.&lt;/p&gt;

&lt;p&gt;As builders of an MLOps platform, we often get asked whether serverless is the right paradigm to deploy models. The cost savings touted by serverless seem extremely appealing for ML workloads as for other traditional workloads. However, the special requirements of ML models as related to hardware and resources can cause impediments to using serverless architectures. To provide the best solution to our customers, we ran extensive benchmarking to compare serverless to traditional computing for inference workloads. In particular, we evaluated inference workloads on different systems including AWS Lambda, Google Cloud Run, and Verta.&lt;br&gt;
In this series of posts, we cover how to deploy ML models on each of the above platforms and summarize our results in our benchmarking blog post.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.verta.ai/blog/how-to-deploy-ml-models-with-aws-lambda"&gt;How to deploy ML models on AWS Lambda&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.verta.ai/blog/how-to-deploy-ml-models-with-google-cloud-run"&gt;How to deploy ML models on Google Cloud Run&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.verta.ai/blog/how-to-deploy-ml-models-on-the-verta-platform"&gt;How to deploy ML models on Verta&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.verta.ai/blog/serverless-for-ml-inference-on-kubernetes-panacea-or-folly"&gt;Serverless for ML Inference: a benchmark study&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post talks about how to get started with deploying models on Google Cloud Run, along with the pros and cons of using this system for inference.&lt;/p&gt;
&lt;h1&gt;
  
  
  What is Google Cloud Run?
&lt;/h1&gt;

&lt;p&gt;Cloud Run is a serverless application running in a container. Cloud Run allows containerized applications to run either on a managed container service or in a customer’s (k8s) kubernetes cluster via Anthos. Cloud Run is powered by Knative, which bills itself as a “Kubernetes-based platform to deploy and manage modern serverless workloads.” Knative supports various service mesh frameworks but in the case of Cloud Run is using the Istio k8s service mesh. Cloud Run allows containerized applications to support modern serverless workloads including scale-to-zero and request concurrency scaling. Cloud Run is the paid / managed version of knative / istio / k8s allowing teams to leverage modern autoscaling container technology without any of the hassle of running the infrastructure.&lt;/p&gt;
&lt;h1&gt;
  
  
  How is Google Cloud Run appealing?
&lt;/h1&gt;

&lt;p&gt;Pros&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No infrastructure (in the case of fully managed)&lt;/li&gt;
&lt;li&gt;Dashboards / logs / revision history (in the case of fully managed or on customer’s Anthos cluster)&lt;/li&gt;
&lt;li&gt;Cost that scales linearly with usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limits (that cannot be changed) and Quotas (which can be &lt;/li&gt;
&lt;li&gt;requested to change) to put constraints on what kind of &lt;/li&gt;
&lt;li&gt;models that can be run&lt;/li&gt;
&lt;li&gt;Cold starts, because serverless&lt;/li&gt;
&lt;li&gt;Cold starts occur, even with steady traffic&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Getting started with Google Cloud Run
&lt;/h1&gt;

&lt;p&gt;Creating an endpoint with Google Cloud Run is very similar to creating an always-on container based deployment. But before we can deploy anything we need to perform some Google Cloud Platform setup.&lt;/p&gt;
&lt;h1&gt;
  
  
  Platform Requirements
&lt;/h1&gt;

&lt;p&gt;You will need to create a GCP account, attach billing information and create a project. If you are a new GCP user then you are in luck-- you will receive $300 in credits to use for your first year!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/gcp/"&gt;Sign up here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be prompted to create a project, but if you skip that step or want to create a separate project for this exercise, then go &lt;a href="https://console.cloud.google.com/projectcreate"&gt;create a project&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Software Requirements
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/sdk/gcloud"&gt;gcloud CLI&lt;/a&gt; will be used to build and deploy.&lt;/p&gt;

&lt;p&gt;First, let’s login and create a new gcloud project (to make cleaning things up easier)&lt;/p&gt;

&lt;p&gt;Log into gcloud:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud auth login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A browser should open prompting you to log into your google account. If authentication is successful you should see the google cloud console landing page in your browser. Return to the terminal and set the current project where PROJECT_ID is the project you created earlier.&lt;/p&gt;

&lt;p&gt;Set default project for further commands:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;project PROJECT_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using a separate project is a good idea so that we can find everything we started in order to clean up our account and avoid perpetual charges.&lt;/p&gt;

&lt;p&gt;At this time we can also set a default region for Cloud Run. Feel free to use a different region closer to you.&lt;/p&gt;

&lt;p&gt;Set the run/region:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;run/region us-central1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you have a POSIX terminal (linux / mac / windows wsl)  you can save off the project ID for later use:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;gcloud config get-value project&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Finally, let’s create a directory for some files we’ll add soon.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;cloudrun_example
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;cloudrun_example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  NLP example (DistilBERT)
&lt;/h1&gt;

&lt;p&gt;For this blog post we will set up DistilBERT and perform question and answer predictions.&lt;/p&gt;

&lt;p&gt;There are two python source files, the bootstrap to download and save the model file and the app to serve predictions. Having a separate bootstrap script that we run before creating the endpoint step will greatly improve the cold start time of the endpoint by skipping the need to download the entire model before servicing a request.&lt;/p&gt;

&lt;p&gt;Create these files in your cloudrun_example folder: &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;There should be three files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cloudrun_example&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;app.py bootstrap.py Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile references two python scripts from earlier-- bootstrap.py and app.py. Because we have gcloud installed we can offload the docker build and publish to Google Cloud Build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cloudrun_example&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud builds submit &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us.gcr.io/&lt;span class="nv"&gt;$PROJECT_ID&lt;/span&gt;/distilbert:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command completes with a SUCCESS then the docker container has been built and published. If there is an error, then a google search of the error should lead you quickly towards the answer.&lt;/p&gt;

&lt;p&gt;We are now ready to deploy a cloud run endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cloudrun_example&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud run deploy distilbert &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;gcr.io/&lt;span class="nv"&gt;$PROJECT_ID&lt;/span&gt;/distilbert:latest &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--platform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;managed &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--concurrency&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--set-env-vars&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;MKL_NUM_THREADS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2,OMP_NUM_THREADS&lt;span class="o"&gt;=&lt;/span&gt;2,NUMEXPR_NUM_THREADS&lt;span class="o"&gt;=&lt;/span&gt;2 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--cpu&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3G &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--allow-unauthenticated&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, the terminal will return the URL of the new endpoint. e.g. &lt;a href="https://distilbert-3bz2zvlxbq-uc.a.run.app"&gt;https://distilbert-3bz2zvlxbq-uc.a.run.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are now ready to make a prediction! Try it out:&lt;/p&gt;

&lt;p&gt;curl -d '{"context":"Roses are red, Violets are blue, Sugar is sweet, And so are you.", "question":"What am I?"}' -H "Content-Type: application/json" -X POST &lt;a href="https://distilbert-3bz2zvlxbq-uc.a.run.app/predict"&gt;https://distilbert-3bz2zvlxbq-uc.a.run.app/predict&lt;/a&gt;&lt;br&gt;
Responds with:&lt;/p&gt;

&lt;p&gt;"sugar is sweet , and so are you"&lt;/p&gt;

&lt;h1&gt;
  
  
  Cloud Run limitations
&lt;/h1&gt;

&lt;p&gt;Now that we’ve seen how easy it is to deploy a serverless ML application to Cloud Run, let’s have some real talk on some limitations. Cloud Run, being a platform that targets a wide variety of applications comes with a set of defaults and constraints that preclude some ML workloads. For example, the max CPUs that can be requested is 4 and the max memory is 4G. When deploying a ML workload, one will probably want to dive into settings to lower container concurrency which is the number of open requests per container. The maximum response time for Google Cloud Run is 60 minutes. While there is no container size limit, containers must be able to load and start within 5 minutes. Cloud Run containers are given 10s to terminate before being forcefully terminated.&lt;/p&gt;

&lt;p&gt;Reference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default Quotas &lt;a href="https://cloud.google.com/run/quotas"&gt;https://cloud.google.com/run/quotas&lt;/a&gt;
Container Contract: &lt;/li&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/run/docs/reference/container-contract"&gt;https://cloud.google.com/run/docs/reference/container-contract&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When building this example, issues with long cold starts necessitated the bootstrap.py file to preload the model into the container. While running benchmarks, it was noted that Cloud Run seemed to suffer from “continuous cold starts” such that even with a very steady throughput, new instances would continuously spin up and the unlucky requestor to that instance would have to wait ~10s for a response. Because of this, cloud run is never able to truly achieve a steady state. It would appear that pods are continuously recycled. In Cloud Run there exists no configuration to customize this behavior compared to a self hosted Knative installation.&lt;/p&gt;

&lt;h1&gt;
  
  
  On Rolling one’s own Knative vs Cloud Run
&lt;/h1&gt;

&lt;p&gt;Since Cloud Run is built almost entirely on open source technologies, one could choose to install and configure their own k8s cluster, ingress controllers, Istio and Knative to run their own “serverless” workloads directly. Of course to call such an installation “serverless” actually demonstrates how ridiculous the term “serverless” actually is. Of course there are servers… but when using a managed serverless platform like Cloud Run what you, as the customer, release is the responsibility of directly managing server infrastructure. Because Cloud Run is mostly built on open source technologies you always have the choice to host your own infrastructure to run similar workloads.&lt;/p&gt;

&lt;p&gt;However, this author will confirm that teams looking to go this route are in for quite the ride. Configuring and running k8s, Istio and Knative are all non-trivial tasks. When you go with a managed platform, like Cloud Run, the intricacies of these platforms are mostly hidden from the user. Self hosting will open up a world of knobs and switches that can be set. While this can be a huge advantage to teams needing to highly tune specialized workloads, for most use cases is a big deep rabbit hole of testing, tuning and more testing.&lt;/p&gt;

&lt;p&gt;Not yet afraid? Well we haven’t even covered logs, metrics, revision control and dashboards. With Cloud Run you get web and command line tools for viewing and managing your workloads. These tools are the part of the k8s / Istio / Knative stack that is not open source. Now you are on the hook to add all of these to be able to effectively manage and provide visibility to your workloads.&lt;/p&gt;

&lt;p&gt;If one insists on setting up their own infrastructure, then consider taking a look at Anthos. Anthos is yet another installation on a k8s cluster that provides a rich set of integration with Google Cloud Console. An Anthos enabled cluster can be deployed via the Google Cloud Console Cloud Run dashboard as well as connect with all of Google Cloud’s existing monitoring tools. With Anthos customers can control and customize their Knative installation while also having access to all of Google's proprietary console tools.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Google Cloud Run is great for the use cases that fit within the container contract. Because Google Cloud Run is built on top of open source technologies, there is also a path towards self-hosting. In addition, since Cloud Run can scale to zero, you pay as you go. However, you will end up paying more for that compute compared to simply buying Google Cloud Compute instance outright and hosting the service directly. In this case you would also create a floor on expense because you would not be scaling to zero.&lt;/p&gt;

&lt;p&gt;Google Cloud Run, with its default settings, might be best suited for smaller HTTP workloads than machine learning. There are hard limits to CPU and memory that prevent running larger ML workloads. The default request concurrency (80) makes sense for parallelizable workloads but will create serious issues for ML workloads. Care should be taken when creating the deployable container to ensure that the container is able to start, run and stop within the constraints of Cloud Run.&lt;/p&gt;

&lt;p&gt;Stay tuned for our next blog in this series!&lt;/p&gt;

&lt;h1&gt;
  
  
  Author biography
&lt;/h1&gt;

&lt;p&gt;John spent over ten years in the enterprise software/embedded/mobile development tools space before transitioning to fullstack web development for the past ten years. John currently leads the frontend team at Verta.&lt;/p&gt;

&lt;h1&gt;
  
  
  About Verta
&lt;/h1&gt;

&lt;p&gt;Verta provides AI/ML model management and operations software that helps enterprise data science teams to manage inherently complex model-based products. Verta’s production-ready systems help data science and IT operations teams to focus on their strengths and rapidly bring AI/ML advances to market. Based in Palo Alto, Verta is backed by Intel Capital and General Catalyst. For more information, go to &lt;a href="http://www.verta.ai"&gt;www.verta.ai&lt;/a&gt; or follow @VertaAI.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>devops</category>
      <category>mlops</category>
      <category>googlecloud</category>
    </item>
    <item>
      <title>Mastering the Code Pair Interview</title>
      <dc:creator>John Dean</dc:creator>
      <pubDate>Thu, 30 Apr 2020 05:00:13 +0000</pubDate>
      <link>https://forem.com/captemulation/mastering-the-code-pair-interview-2k1o</link>
      <guid>https://forem.com/captemulation/mastering-the-code-pair-interview-2k1o</guid>
      <description>&lt;p&gt;Many companies incorporate a code pair exercise where the applicant must solve a coding riddle. I gave 50+ of these as the interviewer before myself needing to enter the job market where I interviewed with more than a dozen companies and completed many code pair exercises as part of the interview process. In this article I attempt to demystify this process, explain what interviewers want to see as well as provide some strategies for mastering the code pair interview.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Process
&lt;/h2&gt;

&lt;p&gt;An applicant will typically go through one or more screening calls before being assigned a code pair exercise. Sometimes the applicant will receive a takehome assignment before the code pair exercise. If the applicant passes these initial screenings then the next step may be a code pairing exercise. &lt;/p&gt;

&lt;p&gt;Code pairing exercises range from super simple to devilishly complex. Typically the level of the role you are applying for will largely dictate the complexity of the problem, but some companies prefer to give difficult problems to see how candidates perform under pressure. However, even easy questions can be a strong source of stress for the nervous applicant. &lt;/p&gt;

&lt;p&gt;After meeting the interviewers the applicant will typically be asked to log into a code pairing website where everyone can see the code as it is being typed and run the code to receive a result. Some requirements and often times some data is provided to the applicant and some, &lt;em&gt;but not all&lt;/em&gt;, requirements for a correct solution listed. Usually standard input and output functions of the language (e.g. printf or console.log) are used to output results. The applicant is given a set amount of time to complete the exercise and achieve the correct output.&lt;/p&gt;

&lt;p&gt;Sometimes there will be follow up requirements if the applicant solves the exercise early.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Anatomy of a Code Pair Exercise
&lt;/h2&gt;

&lt;p&gt;There are many pre-existing repositories of coding problems to choose from but also common for individual interviewers or companies to have their own set exercises. Fear not because of the format of code pairing exercises there tends to be a limited set of problems companies can reasonable expect applicants to finish assuming a 30-60 minute window. &lt;/p&gt;

&lt;p&gt;The most common exercise will involve the applicant working with some data (lists, objects, strings, numbers etc..)-- either to generate data, transform data or both. The goal of the applicant will typically be to map requirements into code that is generating and/or consuming some kind of data and to achieve the expected output.&lt;/p&gt;

&lt;p&gt;The traditional code pair exercise revolved around core CS data structure concepts, e.g. all the kinds of trees and lists. My experience is that these sort of questions are not used much anymore. &lt;/p&gt;

&lt;p&gt;In the end the applicant is being asked to implement an algorithm to carry out a task. There will usually be preferred algorithms (solutions) that are kept hidden from the applicant. It is task of the applicant to create a solution within the time period but also the applicant is being judged on much more than their code! &lt;/p&gt;

&lt;p&gt;Interviewers want to see how the applicant approaches problems, listen to their thought process and be able to discuss multiple solutions. Knowing what interviewers are looking for will help the applicant pass the interview even if the exercise was not completed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparation
&lt;/h2&gt;

&lt;p&gt;Understand the language you will need to use for the exercise. Sometimes there is a choice and other times the preferred language of the role is used. Be able to write code in the chosen language without needing to lookup language features and syntax during the exercise. The goal should be to spend the majority of the time on the problem, not fighting the language. &lt;/p&gt;

&lt;p&gt;Understand algorithms and data structures. Interviewers are often looking for certain key phrases and these key phrases will all be found in the wonderful world of algorithms and data structures. If you feel like you need a refresher or need to know more, check out these free courses online:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/specializations/algorithms"&gt;https://www.coursera.org/specializations/algorithms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/data-structures"&gt;https://www.coursera.org/learn/data-structures&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of the open nature of code pairing exercises one can never really be fully prepared, but there are many things one can do to be ready. It shouldn't need mentioning but obviously be well rested. Try to schedule the interview at a time that is convenient. Have water and/or coffee at the ready. Expect to do a fair amount of talking during the interview.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Requirements
&lt;/h2&gt;

&lt;p&gt;The applicant is often given incomplete requirements. Ask questions! Asking the right questions to clarify the requirements is often part of the excercise. &lt;/p&gt;

&lt;p&gt;If your exercise involves transforming data, a good first questions is to ask, "can I assume that the data is always correctly formatted or do I need to account for bad data". This is a great question because usually the answer is to assume that the incoming data is always correct. This will save a bunch of time. A good response is "Thanks! I'll assume that the data is coming from a well tested module."&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding Solutions
&lt;/h2&gt;

&lt;p&gt;The quickest way to find a solution to a given code pairing exercise is to google the requirements. Chances are the question being asked has already been documented and solved in multiple languages. But let's assume you are not going to be able to do so. After all the applicant is being watched. Don't assume that just because you are remote that no one will notice the darting of eyes or the reflection of another screen at the ready. &lt;/p&gt;

&lt;p&gt;Have a plan! First off do a systems check. Make sure code can be run and results returned. Next, start clarifying requirements.  Document any changes to requirements. Next, write stub function/class which to create a general outline that needs finishing. Try to keep talking. Discuss naming. Otherwise just talk through what you are doing. Next, write some failing tests. TTD (Test Driven Development) is not nearly as popular as it once was so the test is not to show that you know TDD (but feel free to mention it if you want!) but to &lt;em&gt;make sure there is a test written&lt;/em&gt; in case you run out of time. Having a test, like code comments, is part of writing good clean code which is the end goal.&lt;/p&gt;

&lt;p&gt;After thinking through the requirements and asking questions, hopefully a plan is forming. A standard question of the interviewer will be to question the applicant on their solution's time and memory complexity (big O notation-- see algorithms). Get in front of those questions and declare the complexity of different approaches. At this time, don't about follow up requirements. The first goal is always to achieve a working solution for the presented exercise. &lt;/p&gt;

&lt;p&gt;Write down your plan as rough pseudo code as code comments. It's OK to be a little vague if some part of the plan is unknown. Mark it as such and move on. &lt;/p&gt;

&lt;p&gt;Now the real challenge begins.&lt;/p&gt;

&lt;p&gt;Most solutions will involve some amount of iteration-- either a for loop, do...while loop or some kind of recursion. Look for a solution in that order. A for loop is safest because they tend have defined entry and exit parameters. do...while loops are common in these exercises but caution is needed when using them both in a code pairing exercise and in real life! Be sure to really think about how to exit a do...while loop else spend extra time dealing with a locked/crashed program. Recursion is usually a trap both in a code pairing exercise and the real world. When reaching for a recursive solution, additional requirement clarification is needed. The problem with a recursive solution is that they depend on the execution stack which tends to have much smaller memory footprint than the heap which is where general memory allocations come from. Fret not! Recursive solutions can typically be converted into a loop and a stack allocated on the heap to maintain the state stored in the execution stack of a recursive algorithm. &lt;/p&gt;

&lt;p&gt;If the current solution involves iterating over the same data over and over then this is a sign that the solution is not going to be time and/or memory efficient. At this point take a step back and consider how fix it. The question will come. If this problem is identified early enough and there is enough time, switch to the a more efficient solution. If you are already well through your existing solution then I recommend completing the assignment as-is but first document the limitation and if possible, the solution as code comments.&lt;/p&gt;

&lt;p&gt;By far, the most common solution to resolving time complexity is through the use of a hash map. Be on the lookout for ways to use a hash map to avoid having to re-iterate over data by looking up data in the hash map by key. Often times the solution involves specific methods for generating those keys for the hash map. Another other common solution to resolving complexity is through use of an up-front sort. Always look to see if the problem can be solved efficiently if the data was in a certain order. Sometimes the answer involves both! In my last set of interviews I had a couple of solutions that involved using a hash map and sorting a small data set (2 or 3 variables) to use as a key. &lt;/p&gt;

&lt;h2&gt;
  
  
  What To Do When Stuck?
&lt;/h2&gt;

&lt;p&gt;We'd all like to ace these problems effortlessly with a correct and efficient solution. If that happens then great! If not, then don't panic! Getting stuck is completely normal and often expected. &lt;/p&gt;

&lt;p&gt;I think the most important thing to do, and this takes practice, is to talk out loud as much as possible. Avoid "dead space" where there is no typing and no talking. Always be doing one or both! Usually when I'm stuck I start by talking out loud what the code I have so far does. Hopefully at this point you already have a general plan and some pseudo code. If I don't know what to do I will often simply compare my own code to the psuedo code. The questions I will ask myself are "Does my code implement the pseudo code?" and "What am I missing?". Maybe the pseudo code was incomplete. Add more detail if possible.&lt;/p&gt;

&lt;p&gt;There is no shame in admitting you are stuck. Simple say or type "I am stuck &lt;em&gt;here&lt;/em&gt;" where &lt;em&gt;here&lt;/em&gt; is a specific spot in the code. I would try to avoid asking for a hint too early on. Often times you can get hints without asking simply be talking through the problem. Listen and watch the interviewers. Look and listen for confirmation that an idea is correct or incorrect. If there are no "free" hints then ask for a hint. While it will be noted it is not necessarily a bad thing. After all no one wants software developers that spin their wheels and don't ask for help.&lt;/p&gt;

&lt;p&gt;If no actionable hints are forthcoming and there is still more to implement-- then finish what parts of the solution you can. If you can create smaller tests for some part of the solution then that is better than providing no solution at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Touches
&lt;/h2&gt;

&lt;p&gt;No matter if the exercise is solved or not there are certain attributes a final solution to have. Usually the final code will be saved to be reviewed later. There should be tests and their should be code comments. My experience is that most applicants write code with zero code comments or with little testing. Having participated in many of the discussions that applicants are not privy to I can state unequivocally that good code carries more weight than a correct solution. Think of it this way... If there are multiple applicants with the correct solution, then the applicant with better code wins. In addition, I would be more interested in an applicant that wrote clean, well commented code over someone who quickly banged out a solution. There is always an assumption that the applicant might already know the solution in which chase a bare bones solution might look like a solution that was from rote memory rather than a creative enterprise. &lt;/p&gt;

</description>
      <category>coding</category>
      <category>interview</category>
    </item>
    <item>
      <title>Developing and deploying create-react-app to multiple Firebase environments</title>
      <dc:creator>John Dean</dc:creator>
      <pubDate>Thu, 12 Sep 2019 05:19:49 +0000</pubDate>
      <link>https://forem.com/captemulation/developing-and-deploying-create-react-app-to-multiple-firebase-environments-4e8h</link>
      <guid>https://forem.com/captemulation/developing-and-deploying-create-react-app-to-multiple-firebase-environments-4e8h</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;create-react-app makes it easy to quickly get started with React. Firebase makes it easy to quickly get started with web deployments. This article will show how to configure, build and deploy a React app to multiple environments in Firebase. Plus we will get it all working well together with Typescript.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;First we need to install some tools. These instruction assume a unix terminal prompt. For windows, install WSL (Windows Subsystem for Linux) from the Windows app store&lt;/p&gt;

&lt;h2&gt;
  
  
  Install NodeJS
&lt;/h2&gt;

&lt;p&gt;If you already have NodeJS installed, you can skip ahead. If not head on over to &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;nodejs.org&lt;/a&gt; and download an installer or use &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt; to be able to future-proof your NodeJS installation.&lt;/p&gt;

&lt;p&gt;Using nvm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart your terminal or follow the instructions on the terminal. Then install node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install 12 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run create-react-app
&lt;/h2&gt;

&lt;p&gt;If you already have an application then you can skip these and go to installing Firebase.&lt;/p&gt;

&lt;p&gt;To make some steps easier let's pick a name for our new application which we will save as an environment variable to reuse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export REACT_APP=hello-firebase; # replace with your application's name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use npx and create-react-app to boilerplate a new react application. I recommend using Typescript to enable type-checking&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app ${REACT_APP} --typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait a little bit while create-react-app gets ready. When finished enter the application directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ${REACT_APP}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install firebase-tools
&lt;/h2&gt;

&lt;p&gt;In order to work with firebase you will need the &lt;code&gt;firebase&lt;/code&gt; command line tool. The easiest way to get it is to install globally with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g firebase-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Create your firebase application
&lt;/h1&gt;

&lt;p&gt;Head on over to &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;console.firebase.google.com&lt;/a&gt; and activate Firebase for your Google account. If you select the &lt;em&gt;Spark&lt;/em&gt; plan then for moderately sized applications there is no cost.&lt;/p&gt;

&lt;p&gt;Once you have activated firebase, go back to the terminal and login:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be presented with a login prompt in your browser. Click &lt;em&gt;Allow&lt;/em&gt; to complete the login&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F23jfjzxj22eijoz00jpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F23jfjzxj22eijoz00jpt.png" alt="Firebase login modal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Firebase environments
&lt;/h2&gt;

&lt;p&gt;If you are just playing around then you can skip this step. When you get serious about developing a real application you will want to create multiple Firebase environments. To start let's create two firebase environments-- a development and production environment. The development environment will be the default environment that can be used for trying out new features and the production environment will the the "stable" customer facing environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase projects:create ${REACT_APP}-production
firebase projects:create ${REACT_APP}-development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firebase environment names must be unique, so if the name you want is not available, try a different name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize Firebase
&lt;/h2&gt;

&lt;p&gt;Now we are ready to initialize firebase inside our create-react-app. Firebase has an interactive application for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now let's just pick &lt;em&gt;Hosting&lt;/em&gt; because that is all I am going to be covering. You can always re-run this command later to add features&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl9l79j2g2dorjwx530q5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl9l79j2g2dorjwx530q5.png" alt="Firebase init component selection screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll use an existing project that we created earlier. If using multiple environments I recommend picking your development environment as the default.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fc7spubd6xlnlb89oad2p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fc7spubd6xlnlb89oad2p.png" alt="Firebase select project interactive screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the hosting location to &lt;em&gt;build&lt;/em&gt;. Answer &lt;em&gt;yes&lt;/em&gt; to if the application is a SPA (single page application). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvug8fazl1fr1wbugqe8x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvug8fazl1fr1wbugqe8x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you going to deploy to multiple environments, then add your secondary environment now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase use --alias production ${REACT-APP}-production; # or whatever name you ended up picking
firebase use default; # switch back to development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Firebase implicit initialization scripts
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Implicit initialization&lt;/em&gt; is a nifty way to initialize Firebase without config files. When supporting multiple configurations from a single project it is the only easy way to support multiple configurations. We really do not want to have the following code because it is not a good idea to leak non-production environment details in a production application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (process.env.REACT_APP_DEPLOY_ENV='production') {
  firebase.initializeApp(productionConfig)
} else {
  firebase.initializeApp(developmentConfig) 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Implicit initialization&lt;/em&gt; works by loading Firebase javascript from a special &lt;code&gt;/__/&lt;/code&gt; folder. We we deploy our app to Firebase this route will exist for us but locally we will need to do a little more work to set it up.&lt;/p&gt;

&lt;p&gt;In your favorite code editor open up the &lt;em&gt;build/index.html&lt;/em&gt; that was created by &lt;code&gt;firebase init&lt;/code&gt;. At the top of the body tag you will see a series of Firebase related script tags. Select and copy these tags:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdcqvw1asw0hyej8968lv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdcqvw1asw0hyej8968lv.png" alt="Firebase script config tags selected"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste them in your &lt;em&gt;public/index.html&lt;/em&gt; file at the top of the body tag. Feel free to remove features you are not using. &lt;/p&gt;

&lt;h2&gt;
  
  
  Firebase serve for local development
&lt;/h2&gt;

&lt;p&gt;firebase-tools comes with a server that supports the implicit initialization, but first we need to set up a few things in create-react-app.&lt;/p&gt;

&lt;p&gt;First let's install &lt;code&gt;run-p&lt;/code&gt; which is a handy tool for running multiple npm scripts in parallel. In addition we will need to configure an http proxy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D npm-run-all http-proxy-middleware
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your &lt;em&gt;package.json&lt;/em&gt; change the &lt;code&gt;start&lt;/code&gt; script from &lt;code&gt;react-scripts start&lt;/code&gt; to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "start": "run-p --race dev:firebase dev:react",
    "dev:firebase": "firebase serve -p 4000",
    "dev:react": "react-scripts start",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create &lt;em&gt;src/setupProxy.js&lt;/em&gt; file and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const proxy = require('http-proxy-middleware')

module.exports = function(app) {
  app.use(
    '/__',
    proxy({
      target: 'http://localhost:4000'
    })
  )
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready for local development. In your terminal run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If all is well you should see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcvoxiht95eo09h187rxr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcvoxiht95eo09h187rxr.png" alt="A running react app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checking developer tools and terminal console you should see that Firebase javascript is loading and no errors are present. Hot reloading works so you can make changes to code and they will be reflected immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying Firebase Hosting
&lt;/h2&gt;

&lt;p&gt;We are almost ready to deploy our react app to Firebase hosting. First we need to add a line to &lt;em&gt;firebase.json&lt;/em&gt; to automatically build our application before deploying. Otherwise you will forget to do it. Add the following line to the &lt;code&gt;hosting&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"predeploy": ["npm --prefix \"$RESOURCE_DIR/..\" run build"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk9943qsfpuafc6bxgn5p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk9943qsfpuafc6bxgn5p.png" alt="Firebase config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React will build and a link will be provided in the console. You should be able to click on that link your React application will load!&lt;/p&gt;

&lt;h2&gt;
  
  
  Switching Environments
&lt;/h2&gt;

&lt;p&gt;When you are ready to deploy to production all it takes is an environment switch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase use production; # switches all future firebase commands to production
firebase deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or use the &lt;code&gt;-P&lt;/code&gt; flag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase -P ${REACT_APP}-production deploy; # Does not switch default environment but still deploys to production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Typescript typings
&lt;/h2&gt;

&lt;p&gt;If you start using Firebase in your Typescript application you need to let Typescript know about this global &lt;code&gt;firebase&lt;/code&gt; variable that you know have access to. First install &lt;code&gt;firebase&lt;/code&gt; not to import but simply to get access to the types contained within:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D firebase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create a &lt;em&gt;src/firebase.d.ts&lt;/em&gt; file and copy the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import firebase from 'firebase'

declare global {
  export const firebase = firebase
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have full typescripts bindings available.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this guide makes it easy to use create-react-app together with Firebase for modern web application development combined with free application hosting.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>firebase</category>
    </item>
  </channel>
</rss>
