<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by nish abe on Medium]]></title>
        <description><![CDATA[Stories by nish abe on Medium]]></description>
        <link>https://medium.com/@nishabe?source=rss-2d938a3ec7e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jr2LWniAp-qbqAgZZHuCEw.png</url>
            <title>Stories by nish abe on Medium</title>
            <link>https://medium.com/@nishabe?source=rss-2d938a3ec7e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:44:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nishabe/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to integrate react native code with an existing iOS app?]]></title>
            <link>https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-ios-app-655c61a65b8c?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/655c61a65b8c</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 19:38:10 GMT</pubDate>
            <atom:updated>2022-08-10T19:41:29.136Z</atom:updated>
            <content:encoded><![CDATA[<p>I was tinkering with react native recently and learned a few things about setting up the dev environment and running it. <a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">This post details</a> my experience. As a next step, I wanted to explore how we can integrate a react native code module into an existing iOS app.</p><p><a href="https://reactnative.dev/docs/integration-with-existing-apps/">Here is the official documentation</a> on how to do it. While it looks just fine, there are a few aspects about it that can be improvised. Not all the steps are needed and the sample app they refer to in the documentation is no longer available on Github. This post is my attempt to fix the shortcomings of the original.</p><p>All the steps below are tested and validated on a MacBook Pro M1 MAX running MacOS Monterey 12.5 with Xcode 13.4.1, Android studio Chipmunk, and Visual Studio Code 1.70.0.</p><p>Please make sure you have your dev environment set up correctly and you are able to run a react native app in an Android emulator or device. This is very important to continue with the next steps. You may <a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">refer to this post </a>in case you need a little bit of help doing it.</p><p>The concept on a high level is to set up the react native dependencies in an accessible folder and then configure the Cocoapods to use those dependencies. Once that is done, use ‘RCTRootView’ to render the react native UI inside the native app.</p><p>Here are the main steps that need to be performed.</p><ol><li>Create a directory structure and set up the dependencies.</li><li>Create a react native component</li><li>Create an iOS project</li><li>Set up dependencies using the pod file</li><li>Add code changes in the native iOS app</li></ol><p>Now the steps in detail:</p><h3>1. Create a directory structure and set up the dependencies.</h3><p>Create a root folder where the react native module and the existing (or new) iOS app coexist.</p><pre>mkdir integratedReactNativeProject</pre><p>Create a package.json file that will have the basic project information and other dependency details.</p><pre>cd integratedReactNativeProject &amp;&amp; touch package.json</pre><p>Open the package.json which is just created in any text editors and add these lines:</p><pre>{<br>  &quot;name&quot;: &quot;MyReactNativeApp&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;private&quot;: true,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;yarn react-native start&quot;<br>  }<br>}</pre><p>If you don’t have it already, install yarn</p><pre>npm i yarn</pre><p>Install the react and react-native packages using yarn.</p><pre>yarn add react-native</pre><p>You can see the log messages being added to the terminal. Search for the word ‘peer’ and note down the dependencies mentioned there. Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GXGKmUJTahU4916l.png" /></figure><p>Based on the above message we need to install babel/core, react18.0.0, babel/preset-env.</p><p>Either add each one of them one by one or install it once.</p><pre>yarn add react@18.0.0  <br>yarn add <a href="http://twitter.com/babel/core">@babel/core</a> <br>yarn add react-native</pre><p>or</p><pre>yarn add <a href="http://twitter.com/babel/preset-env">@babel/preset-env</a> &amp;&amp; yarn add <a href="http://twitter.com/babel/core">@babel/core</a> &amp;&amp; yarn add react@18.0.0</pre><p>Once done, you can see that all these dependencies are added in package.json, and also a node_modules folder is added to the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*oT5aehFyVS6luVvB.png" /></figure><h3>2. Create a react native component</h3><p>In this step, we will create a barebone react-native ‘hello’ world screen.</p><p>Create an index.js file inside the root folder, add the below lines and save it.</p><pre>import React from &#39;react&#39;;<br>import {<br>  AppRegistry,<br>  StyleSheet,<br>  Text,<br>  View<br>} from &#39;react-native&#39;;</pre><pre>const HelloWorld = () =&gt; {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;Text style={styles.hello}&gt;Hello, World&lt;/Text&gt;<br>    &lt;/View&gt;<br>  );<br>};<br>var styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    justifyContent: &#39;center&#39;<br>  },<br>  hello: {<br>    fontSize: 20,<br>    textAlign: &#39;center&#39;,<br>    margin: 10<br>  }<br>});</pre><pre>AppRegistry.registerComponent(<br>  &#39;MyReactNativeApp&#39;,<br>  () =&gt; HelloWorld<br>);</pre><h3>3. Create an iOS project</h3><p>Assuming that you are still inside the root directory, we will create a subfolder called ‘ios’ and within this newly created subfolder add an ios project.</p><pre>mkdir ios</pre><p>Please note that you can either create a brand-new ios app and save it inside this subfolder or just copy and paste an existing ios app project files here.</p><p>I am taking the first option which is creating a new app. Using Xcode, create a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXJeyq-LSqrhWwT8zbszFw.png" /></figure><p>Run the app and make sure it runs on Simulator. I chose the ‘iPhone 13’ simulator. You should see a blank white screen on the simulator.</p><h3>4. Set up dependencies using the pod file</h3><p>If you have not already, now is the time to install cocoapods.</p><pre>brew install cocoapods</pre><p>Once it is done, go to the ‘ios’ folder and init the pods</p><pre>pod init</pre><p>This will generate a pod file. Open the pod file in any text editor and add these lines at the top:</p><pre>require_relative &#39;../node_modules/react-native/scripts/react_native_pods&#39;<br>require_relative &#39;../node_modules/@react-native-community/cli-platform-ios/native_modules&#39;</pre><p>Add the below line under ‘target’ block:</p><pre>use_react_native!</pre><p>The pod file should look like this now:</p><pre>require_relative &#39;../node_modules/react-native/scripts/react_native_pods&#39;<br>require_relative &#39;../node_modules/@react-native-community/cli-platform-ios/native_modules&#39;<br># Uncomment the next line to define a global platform for your project<br># platform :ios, &#39;9.0&#39;</pre><pre>target &#39;MyApp&#39; do<br>  # Comment the next line if you don&#39;t want to use dynamic frameworks<br>  use_frameworks!<br>  use_react_native!</pre><pre># Pods for MyApp</pre><pre>end</pre><p>After you have created your Podfile, you are ready to install the React Native pod.</p><pre>$ pod install</pre><p>You should see the dependencies being installed as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3f3dk1kWrhHG0SGRC5ung.png" /></figure><p>Once over, you will see many files added to the project including a pod project and a new workspace. In this case, ‘MyApp.xcworkspace’.</p><h3>5. Add code changes in the native iOS app</h3><p>Open the ‘MyApp.xcworkspace’ and check if it compiles successfully.</p><p>Open the ViewController.swift, and add an import statement for react</p><pre><strong>import</strong> React</pre><p>Override the loadView() method so that it calls a function that reassigns the ‘view’ to an instance of ‘RCTRootView’.</p><p>The code will look like the below:</p><pre><strong>import</strong> UIKit</pre><pre><strong>import</strong> React</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>}</pre><pre><strong>override</strong> <strong>func</strong> loadView() {</pre><pre>loadReactNativeView()</pre><pre>}</pre><pre><strong>func</strong> loadReactNativeView() {</pre><pre><strong>let</strong> jsCodeLocation = URL(string: &quot;http://localhost:8081/index.bundle?platform=ios&quot;)!</pre><pre><strong>let</strong> rootView =  (</pre><pre>bundleURL: jsCodeLocation,</pre><pre>moduleName: &quot;MyReactNativeApp&quot;,</pre><pre>initialProperties: <strong>nil</strong>,</pre><pre>launchOptions: <strong>nil</strong></pre><pre>)</pre><pre><strong>self</strong>.view = rootView</pre><pre>}</pre><pre>}</pre><p>We are almost there. Assuming that you are still in the root folder, which is ‘integratedReactNativeProject’ in this case, run the below command:</p><pre>yarn start</pre><p>This will start the metro server. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1llWgX3JTZVm9HAGLRsMXg.png" /></figure><p>Please note that the module name, ‘MyReactNativeApp’ here has to be the same as the one provided for <strong><em>AppRegistry.registerComponent()</em></strong> function of index.js file.</p><p>Now, run the app in Xcode.</p><p>If everything is working as expected you should see the ‘hello world’ message on the simulator screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*gmAWIY_EaO8j844JVviSlw.png" /></figure><p>Hope this worked for you.</p><p>What is shown above is the simplest example. Please refer to the <a href="https://reactnative.dev/docs/integration-with-existing-apps">original documentation</a> to know more about how to communicate between react world and the native world. Thanks for your time.</p><p><strong>References:</strong></p><ol><li><a href="https://reactnative.dev/docs/integration-with-existing-apps">Integration with Existing Apps</a></li><li><a href="https://fek.io/blog/how-to-add-react-native-to-an-existing-i-os-app-in-2022">How to add React Native to an existing iOS app in 2022</a></li></ol><p><strong>My other posts about react-native:</strong></p><p><a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">Setting up ReactNative on Mac OSX + Apple Silicon</a></p><p><a href="https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-android-app-45a2b7d60887">How to integrate react native code with an existing Android app?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=655c61a65b8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to integrate react native code with an existing Android app?]]></title>
            <link>https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-android-app-45a2b7d60887?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/45a2b7d60887</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 21:33:47 GMT</pubDate>
            <atom:updated>2022-08-10T19:41:37.610Z</atom:updated>
            <content:encoded><![CDATA[<p>I was tinkering with react native recently and learned a few things about setting up the dev environment and running it. <a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">This post details</a> my experience. As a next step, I wanted to explore how we can integrate a react native code module into an existing Android app.</p><p><a href="https://reactnative.dev/docs/integration-with-existing-apps/">Here is the official documentation</a> on how to do it. While it looks just fine, there are a few aspects about it that can be improvised. I have had a hard time making it work mostly because my exposure to react native and android development was limited. Also, the provided steps in the official documentation are not in sequential order. This post is my attempt to fix it.</p><p>All the steps below are tested and validated on a MacBook Pro M1 MAX running MacOS Monterey 12.5 with Xcode 13.4.1, Android studio Chipmunk, and Visual Studio Code 1.70.0.</p><p>Please make sure you have your dev environment set up correctly and you are able to run a react native app in an Android emulator or device. This is very important to continue with the next steps. You may <a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">refer to this post </a>in case you need a little bit of help doing it.</p><p>The concept on a high level is to set up the react native dependencies in an accessible folder and then configure the Gradle file to point to it. Once that is done, use ‘ReactRootView’ to render the react native UI inside the native app.</p><p>Here are the main steps that need to be performed.</p><ol><li>Create a directory structure and set up the dependencies.</li><li>Create a react native component</li><li>Create an Android project</li><li>Set up dependencies using Maven</li><li>Add permissions in manifest</li><li>Add code changes in the native Android app</li></ol><p>Now the steps in detail:</p><h3>1. Create a directory structure and set up the dependencies.</h3><p>Create a root folder where the react native module and the existing (or new) android app coexist.</p><pre>mkdir integratedReactNativeProject</pre><p>Create a package.json file that will have the basic project information and other dependency details.</p><pre>cd integratedReactNativeProject &amp;&amp; touch package.json</pre><p>Open the package.json which is just created in any text editors and add these lines:</p><pre>{<br>  &quot;name&quot;: &quot;MyReactNativeApp&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;private&quot;: true,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;yarn react-native start&quot;<br>  }<br>}</pre><p>If you don&#39;t have it already, install yarn</p><pre>npm i yarn</pre><p>Install the react and react-native packages using yarn.</p><pre>yarn add react-native</pre><p>You can see the log messages being added to the terminal. Search for the word ‘peer’ and note down the dependencies mentioned there. Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1SC50rmDnbDTZ6YkdIKig.png" /></figure><p>Based on the above message we need to install babel/core, react18.0.0, babel/preset-env.</p><p>Either add each one of them one by one or install it once.</p><pre>yarn add react@18.0.0  <br>yarn add <a href="http://twitter.com/babel/core">@babel/core</a> <br>yarn add react-native</pre><p>or</p><pre>yarn add <a href="http://twitter.com/babel/preset-env">@babel/preset-env</a> &amp;&amp; yarn add <a href="http://twitter.com/babel/core">@babel/core</a> &amp;&amp; yarn add react@18.0.0</pre><p>Once done, you can see that all these dependencies are added in package.json, and also a node_modules folder is added to the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*_z0gJMroRFfbsIGBJ3veZw.png" /></figure><h3>2. Create a react native component</h3><p>In this step, we will create a barebone react-native ‘hello’ world screen.</p><p>Create an index.js file inside the root folder, add the below lines and save it.</p><pre>import React from &#39;react&#39;;<br>import {<br>  AppRegistry,<br>  StyleSheet,<br>  Text,<br>  View<br>} from &#39;react-native&#39;;<br><br>const HelloWorld = () =&gt; {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;Text style={styles.hello}&gt;Hello, World&lt;/Text&gt;<br>    &lt;/View&gt;<br>  );<br>};<br>var styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    justifyContent: &#39;center&#39;<br>  },<br>  hello: {<br>    fontSize: 20,<br>    textAlign: &#39;center&#39;,<br>    margin: 10<br>  }<br>});<br><br>AppRegistry.registerComponent(<br>  &#39;MyReactNativeApp&#39;,<br>  () =&gt; HelloWorld<br>);</pre><h3>3. Create an Android project</h3><p>Assuming that you are still inside the root directory, we will create a subfolder called ‘android’ and within this newly created subfolder add an android project.</p><pre>mkdir android</pre><p>Please note that you can either create a brand-new android app and save it inside this subfolder or just copy and paste an existing android app project files here.</p><p>I am taking the first option which is creating a new app. Using Android Studio, create an ‘Empty activity’ project. I chose the language as Java.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*rIdwthxPCdR_CoUIiLqSRg.png" /></figure><p>Once the Gradle build is over, make sure to run this app in an emulator. I chose ‘Pixel 4 API 33’ which was added to my device manager. Ideally, you should see the screen with a ‘hello world!’ message.</p><h3>4. Set up dependencies using Maven</h3><p>In this step, we need to make changes in a few of the Gradle scripts so that they will point to the react native dependencies saved locally under the node_module folder.</p><p>Open the main Gradle file and add the below lines so that it looks like the screenshot.</p><pre>allprojects <strong>{<br>    </strong>repositories <strong>{<br>        </strong>maven <strong>{<br>            </strong>// All of React Native (JS, Android binaries) is installed from npm<br>            url (&quot;$rootDir/../node_modules/react-native/android&quot;)<br>        <strong>}<br>        </strong>maven <strong>{<br>            </strong>// Android JSC is installed from npm<br>            url(https://medium.com/node_modules/jsc-android/dist&quot;)<br>        <strong>}<br>        </strong>google()<br>        jcenter()<br><br>    <strong>}<br>}</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61HDUmHPSt5Fl-ir3viVXA.png" /></figure><p>Open the app Gradle file and add the below dependencies at the very bottom.</p><pre>implementation &quot;com.facebook.react:react-native:+&quot; // From node_modules<br>    implementation &quot;org.webkit:android-jsc:+&quot;</pre><p>Now in the same file add the below line at the very bottom.</p><pre>apply from: file(&quot;../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle&quot;); applyNativeModulesAppBuildGradle(project)</pre><p>After these two changes the file should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GjOaulJSrP01sP6YRWfqA.png" /></figure><p>Open the gradle.properties file and add the below line:</p><pre>android.enableJetifier=true</pre><p>The file should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqpxqtMB1u47klukebUTFw.png" /></figure><p>Go to settings.gradle and comment on the lines about ‘dependencyResolutionManagement’. Also, add the below line at the very bottom:</p><pre>apply from: file(&quot;../node_modules/@react-native-community/cli-platform-android/native_modules.gradle&quot;); applyNativeModulesSettingsGradle(settings)</pre><p>Finally, the file should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEj4k2fsa8-su10m8r_7Ww.png" /></figure><p>Please run the Gradle sync now. The build should be a success and the app should be running as before.</p><h3>5. Add permissions in manifest.xml</h3><p>Let&#39;s make some changes to the manifest file.</p><p>Next, make sure you have Internet permission in your AndroidManifest.xml:</p><pre>&lt;uses-permission android:name=”android.permission.INTERNET” /&gt;</pre><p>If you need to access the DevSettingsActivity add it to your AndroidManifest.xml:</p><pre>&lt;activity android:name=”com.facebook.react.devsupport.DevSettingsActivity” /&gt;</pre><p>Inside &lt;application &gt; add this line:</p><pre>android:usesCleartextTraffic=&quot;true&quot;</pre><p>Please make sure this setting is only for debug build not release build. This setting ensures that the app can communicate with the metro server while developing.</p><p>Also, change the ‘android:name’ from ‘.MainActivity’ to ‘.MyReactActivity’.</p><p>The manifest file should look like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ny524GkklegFAjNNt_xYxg.png" /></figure><h3>6. Add code changes in the native Android app</h3><p>In the above step, we added the android name ‘MyReactActivity’. Let&#39;s add a new java file with the same name. This is to load the ‘MyReactActivity’ as the first screen when the app is launched.</p><p>Add the below lines of code in the newly added class.</p><pre>package com.example.myapplication;<br>import android.app.Activity;<br>import android.os.Bundle;<br>import android.view.KeyEvent;<br><br>import com.facebook.react.PackageList;<br>import com.facebook.react.ReactInstanceManager;<br>import com.facebook.react.ReactPackage;<br>import com.facebook.react.ReactRootView;<br>import com.facebook.react.common.LifecycleState;<br>import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;<br>import com.facebook.soloader.SoLoader;<br><br>import java.util.List;<br><br><br>public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {<br>    private ReactRootView mReactRootView;<br>    private ReactInstanceManager mReactInstanceManager;<br><br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        SoLoader.init(this, false);<br><br>        mReactRootView = new ReactRootView(this);<br>        List&lt;ReactPackage&gt; packages = new PackageList(getApplication()).getPackages();<br>        // Packages that cannot be autolinked yet can be added manually here, for example:<br>        // packages.add(new MyReactNativePackage());<br>        // Remember to include them in `settings.gradle` and `app/build.gradle` too.<br><br>        mReactInstanceManager = ReactInstanceManager.builder()<br>                .setApplication(getApplication())<br>                .setCurrentActivity(this)<br>                .setBundleAssetName(&quot;index.android.bundle&quot;)<br>                .setJSMainModulePath(&quot;index&quot;)<br>                .addPackages(packages)<br>                .setUseDeveloperSupport(BuildConfig.<em>DEBUG</em>)<br>                .setInitialLifecycleState(LifecycleState.RESUMED)<br>                .build();<br>        // The string here (e.g. &quot;MyReactNativeApp&quot;) has to match<br>        // the string in AppRegistry.registerComponent() in index.js<br>        mReactRootView.startReactApplication(mReactInstanceManager, &quot;MyReactNativeApp&quot;, null);<br><br>        setContentView(mReactRootView);<br>    }<br><br>    @Override<br>    public void invokeDefaultOnBackPressed() {<br>        super.onBackPressed();<br>    }<br><br>}</pre><p>Please note that the module name, ‘MyReactNativeApp’ here has to be the same as the one provided for <strong><em>AppRegistry.registerComponent()</em></strong> function of index.js file.</p><p>We are almost there. Assuming that you are still in the root folder, which is ‘integratedReactNativeProject’ in this case, run the below command:</p><pre>yarn start</pre><p>This will start the metro server. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1llWgX3JTZVm9HAGLRsMXg.png" /></figure><p>If everything is working as expected, you should be seeing the below screen when you run the app in Android Studio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*Ce3fw2F26ProHjuaMFMv8Q.png" /></figure><p>Hope this worked for you.</p><p>What is shown above is the simplest example. Please refer to the <a href="https://reactnative.dev/docs/integration-with-existing-apps">original documentation</a> to know more about how to communicate between react world and the native world. Thanks for your time.</p><p><strong>Miscellaneous issues:</strong></p><p>Issue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cbdb_NKlSZpaiwDQRyKYLA.png" /></figure><p>Solution:</p><p>In the terminal enter:</p><pre>adb reverse tcp:8081 tcp:8081</pre><p>This should resolve it.</p><p>Tip: You can show the debug menu on the Android emulator by executing this command:</p><pre>adb shell input keyevent 82</pre><p><strong>My other posts about react-native:</strong></p><p><a href="https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e">Setting up ReactNative on Mac OSX + Apple Silicon</a></p><p><a href="https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-ios-app-655c61a65b8c">How to integrate react native code with an existing iOS app?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45a2b7d60887" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up ReactNative on Mac OSX + Apple Silicon]]></title>
            <link>https://nishabe.medium.com/setting-up-reactnative-on-macosx-apple-silicon-48e576bacb4e?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/48e576bacb4e</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 23:28:30 GMT</pubDate>
            <atom:updated>2022-08-10T19:41:33.767Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I tried setting up react native on my mac and the process was not a smooth one. I ended up spending more time than I originally planned to make everything work. Here are a few points that I would like to share with you.</p><p>Here is the <a href="https://reactnative.dev/docs/environment-setup">official documentation</a> on the environment setup. While it mostly covers everything, there are certain steps that it misses out on. Obviously, no documentation can cover all the scenarios and potential issues.</p><p>All the steps below are tested and validated on a MacBook Pro M1 MAX running MacOS Monterey 12.5 with Xcode 13.4.1, Android studio Chipmunk, and Visual Studio code 1.70.0.</p><p>There are a few packages that need to be installed on your mac.</p><p>Install <a href="https://brew.sh/">Brew</a> in case you don&#39;t have it. Follow the prompts and instructions carefully including the step to update the .zprofile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFfHCxqKuUpp9P4ZNni8VA.png" /></figure><p>Once Brew is installed use it to install other packages:</p><pre>brew install node<br>brew install watchman</pre><p>Install <a href="https://apps.apple.com/us/app/xcode/id497799835?mt=12">Xcode from Appstore</a> along with Command line tools.</p><p>Install <a href="https://developer.android.com/studio">Android Studio</a>.</p><p>Install Cocoapods by executing the below command in the terminal.</p><pre>sudo gem install cocoapods</pre><p>Cocoapods need ruby runtime which comes by default in mac.</p><p>Once it is installed, make sure to install the below package. This step is needed because we run in Apple silicon.</p><pre>sudo arch -x86_64 gem install ffi</pre><p>The next step is to run the command that creates a react native project.</p><pre>npx react-native init AwesomeProject</pre><p>Normally this will end up in an error screen like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45Sph6VezkMtc_oz5uKOVw.png" /></figure><p>This is again an M1-specific issue that can be fixed by executing the below command.</p><pre>cd ./AwesomeProject/ios &amp;&amp; arch -x86_64 pod install</pre><p>Please note, that this is a one-time step. You don&#39;t need to do it again.</p><p>Just to verify everything is working as it should, let&#39;s create one more project — this time using the ‘typescript’ template.</p><pre>npx react-native init AwesomeTSProject --template react-native-template-typescript</pre><p>You should see the below screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-zelfXCZ6dmZS5ndpMFPw.png" /></figure><p>As per onscreen instruction, let&#39;s try running the application on the iOS simulator.</p><pre>cd &quot;AwesomeTSProject&quot; &amp;&amp; npx react-native run-ios</pre><p>At this point, I got an error like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*gG5d-MHejhl5We_qrpSu4w.png" /></figure><p>If you see this, you can click on the OK button on the message above and continue loading the app. This can be resolved by <strong>unchecking</strong> the ‘Simulator lifetime’ option in Simulator preferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P5NoqRonVLj2ij1X5TZfUw.png" /></figure><p>As the command is executing in the terminal, it will spin up one more terminal instance window to run the ‘metro’ server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMlhAsdcegxO6ps2xtt8VA.png" /></figure><p>Finally, you should see the app running on the iOS simulator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*39mf_Q9LeLHxbmOEqWxR2w.png" /></figure><p>Note: In my experience, ‘iPod Touch 7th generation’ was consistently throwing build errors. Any other simulator should work.</p><p>Now let&#39;s try running the same app in Android Emulator.</p><p>Assuming that you have already installed Android Studio, open Device Manager and start an emulator. My suggestion is to download Pixel 4 with API version 33.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*bkvxzT9mb-zS3VGwOrOFZA.png" /></figure><p>Now, run the below command:</p><pre>cd &quot;AwesomeTSProject&quot; &amp;&amp; npx react-native run-android</pre><p>For me, this resulted in an error as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNOBLBpSpkDxlh9Cxd5kGg.png" /></figure><p>What happens here is certain tasks need Java11, while on the mac I had only Jave version 1.8 which comes by default. This means you need to download the Java 11 runtime from <a href="https://www.oracle.com/java/technologies/downloads/">Oracle</a>. Please note that you need an account and sign in to Oracle to download Java.</p><p>I downloaded ‘jdk-11.0.15.1_osx-x64_bin.dmg’ and installed it.</p><p>While trying to run the app again, I got another error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQE3gn8fR0EbQB72X0Ckkw.png" /></figure><p>In order to fix that go to the Gradle settings and change the SDK option.</p><p>Navigate to Android Studio -&gt; Preferences-&gt; Build,Execution, Deployment-&gt; Build Tools -&gt; Gradle.<br>From the Gradle SDK dropdown option, select ’Android Studio Default JDK version 11.0.12&#39; as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1mkm_MysgKo680lmJNg-ig.png" /></figure><p>Now try again the run command:</p><pre>cd &quot;AwesomeTSProject&quot; &amp;&amp; npx react-native run-android</pre><p>If all is good, you should see the Android emulator running the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*nE4nXxNDpEnsuSIvytfc_g.png" /></figure><p>Miscellaneous issues:</p><pre>✖ Downloading template<br>error Error: Command failed: yarn add react-native@latest<br>error Couldn&#39;t find package &quot;react-native&quot; on the &quot;npm&quot; registry.<br>yarn add v1.22.19<br>info No lockfile found.<br>[1/4] Resolving packages...<br>info Visit <a href="https://yarnpkg.com/en/docs/cli/add">https://yarnpkg.com/en/docs/cli/add</a> for documentation about this command.</pre><p>Solution: Check the .npmrc configuration. Try directly connecting to npm registry than via an artifactory repo manager.</p><pre>dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 0x0009): tried: &#39;/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle&#39; (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64))) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (LoadError)</pre><p>Solution: Install M1 specific ffi package as we have discussed.</p><pre>Error:<br>&gt; Task :react-native-gradle-plugin:compileKotlin FAILED<br>&#39;compileJava&#39; task (current target is 1.8) and &#39;compileKotlin&#39; task (current target is 11) jvm target compatibility should be set to the same Java version.<br>1 actionable task: 1 executed</pre><pre>Error:<br>error Failed to install the app. Make sure you have the Android development environment set up: <a href="https://reactnative.dev/docs/environment-setup">https://reactnative.dev/docs/environment-setup</a>.<br> Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081</pre><p>Solution: Install JDK11 and set the correct version in Android Studio as we have discussed before.</p><pre><strong>error</strong> Failed to build iOS project. We ran &quot;xcodebuild&quot; command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening...</pre><p>Solution: If you have selected iPod Touch simulator, change it to something else.</p><p>Note: The security application such as Zscalar will block the communication between the metro server and the app. You may need to disable it temporarily during development. Microsoft OneDrive on mac can adversely affect if the app running from a folder that is set for cloud sync. I have seen in some forums where many folks mentioned that ‘McAfee’ causing issues.</p><p>Hope this helps!</p><p><strong>My other posts about react-native:</strong></p><p><a href="https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-ios-app-655c61a65b8c">How to integrate react native code with an existing iOS app?</a></p><p><a href="https://nishabe.medium.com/how-to-integrate-react-native-code-with-an-existing-android-app-45a2b7d60887">How to integrate react native code with an existing Android app?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48e576bacb4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit testing a NestJS App —  In shortest steps.]]></title>
            <link>https://nishabe.medium.com/unit-testing-a-nestjs-app-in-shortest-steps-bbe83da6408?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbe83da6408</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[supertest]]></category>
            <category><![CDATA[e2e-testing]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 16:08:38 GMT</pubDate>
            <atom:updated>2022-05-23T03:37:53.309Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unit testing a NestJS App — In shortest steps.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*UtTcV_ovz4AFy2bik4ddaQ.png" /></figure><p>Developing a NestJS app is a joyful experience. Let&#39;s see how we can add unit tests and end-to-end tests to a NestJS application. I have learned a lot from <a href="https://blog.theodo.com/2019/06/test-nestjs-with-jest-typescript/">this article</a> written by <a href="https://blog.theodo.com/d%C3%A9bora-barreto-ornellas">Débora Barreto Ornellas</a> and this write-up is based mostly on it.</p><p>There are five high-level steps that we need to do.</p><ol><li>Create a sample NestJS application</li><li>Add unit test cases</li><li>Run unit test cases</li><li>Add end to end test cases</li><li>Run all tests</li></ol><p>Detailed steps below:</p><h3>1. Creating a sample NestJS application</h3><p>Let&#39;s start by creating a NestJS application called ‘StudentGPA’. Go to your folder and run the below command in the VSCode terminal.</p><pre>nest new StudentGPA</pre><p>Create two services by executing the below commands:</p><pre>nest g service student<br>nest g service api</pre><p>Also, do an npm install and make sure the project runs as expected:</p><pre>npm install<br>nest start</pre><p>After confirming that the app is running,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*az1PbLU6Ydz_R3lvPq4ROg.png" /></figure><p>your file explorer will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*yxhr4U--zc1gmfs9IuwUdQ.png" /></figure><p>The concept of this app is simple. The class <strong>StudentService</strong> defined in <em>student.service.ts</em> defines a function that accepts the first name and second name of the student and returns the GPA. The <strong>StudentService</strong> class uses the other class called ‘<strong>ApiService</strong>’ defined in <em>api.service.ts </em>to get the student information. In real scenarios, this class will be communicating with a database or another microservice.</p><p>The annotated files are the test files that are automatically created. Please note the extension, <em>.spec.ts</em>. Unit testing is made possible in NestJS by using another framework called <a href="https://jestjs.io/">JestJS</a>. The Jest framework search for the files with these extensions.</p><p>As a first step let&#39;s focus only on writing unit tests. This means we will be working in <em>app.controller.ts</em>, <em>student.service.ts</em>, and <em>api.service.ts</em>. We also need to add the getGPA function to the controller class so that it is available for consumers.</p><p>A modified app.controller.ts (AppController class) will look like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fae04198368795e67bd26700e4bdf4f0/href">https://medium.com/media/fae04198368795e67bd26700e4bdf4f0/href</a></iframe><p>Now, we need to add ‘getGpa’ in ‘<em>studentService</em>’. Once added, <em>studentService</em> (<em>student.service.ts</em>) will look like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bacd30a18a79cab349b03b8b8cb44971/href">https://medium.com/media/bacd30a18a79cab349b03b8b8cb44971/href</a></iframe><p>As you can see on line# 14, we are calling ‘<em>getStudent</em>’ method of ‘<em>api.service</em>’.</p><p>Now, <em>ApiService</em> class will look like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62e073f53cc275c8a9f9ba3cd1538e59/href">https://medium.com/media/62e073f53cc275c8a9f9ba3cd1538e59/href</a></iframe><p>You may notice that in Line#8, the url variable is incorrect. The exact value does not matter because our focus is on unit testing and in the unit testing, we will never hit the real endpoints.</p><p>Please do a ‘nest start’ to make sure everything is working as expected.</p><h3>2. Adding unit test cases</h3><p>Before we begin, let&#39;s refresh the basic concepts of unit testing.</p><p>Unit testing focuses on writing tests for the smallest possible units. In most cases, they are functions defined in classes. MethodA in a class may be calling MethodB in another class. However, a unit test of MethodA is focused only on the logic of MethodA, not MethodB. Unit tests shouldn’t be dependent on the environment in which they are being run, and they are supposed to be fast. To write isolated unit tests, it’s common to mock all dependencies of a method/service. In the <em>StudentService</em> unit test, we’ll mock <em>ApiService</em> by creating an <em>ApiServiceMock</em> class.</p><p><strong>Test Doubles</strong>: Fakes, stubs, and mocks all belong to the category of test doubles. A test double is an object or system you use in a test instead of something else.</p><p><strong>Fakes</strong>: an object with limited capabilities (for the purposes of testing), e.g. a fake web service. Fake has business behavior. You can drive a fake to behave in different ways by giving it different data. Fakes can be used when you can’t use a real implementation in your test.</p><p><strong>Mock: </strong>an object on which you set expectations. A mock has expectations about the way it should be called, and a test should fail if it’s not called that way. Mocks are used to test interactions between objects.</p><p><strong>Stub: </strong>an object that provides predefined answers to method calls. A stub has no logic and only returns what you tell it to return.</p><p>In case you are interested, <a href="https://stackoverflow.com/questions/346372/whats-the-difference-between-faking-mocking-and-stubbing">here</a> is a good discussion on fake/mock/stub.</p><p><strong>Spy: </strong>Spy, spies on the caller. Often used to make sure a particular method has been called.</p><p>For unit tests, we will focus on three classes, which are: <strong>app.controller.spec.ts</strong>(Test class of <em>AppController</em>), <strong>student.service.spec.ts</strong>(Test class of <em>StudentService</em>), and <strong>api.service.spec.ts</strong> (Test class of <em>ApiService</em>).</p><p>There are multiple approaches that we can take here. One of them is using <a href="https://jestjs.io/docs/en/mock-functions">Mock functions</a> provided by the Jest framework. Mock functions allow you to test the links between code by erasing the actual implementation of a function. Another one is using mock classes.</p><p>Let&#39;s explore the mock function approach in <strong>app.controller.spec.ts.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ba4e34983b46c5fa8377e5897d33b50/href">https://medium.com/media/0ba4e34983b46c5fa8377e5897d33b50/href</a></iframe><p>Line#1: The ‘Test’ class from ‘<a href="http://twitter.com/nestjs/testing">@nestjs/testing</a>’ provides a test execution context by mocking the full Nest runtime. It also provides hooks to help mock and overriding.</p><p>Line#8: A variable called ‘spyService’ is declared for spying the invocation of ‘StudentService</p><p>Line#17-20: The compile method of this object bootstraps a module with its dependencies and returns a module that is ready for testing.</p><p>Line#23: spyService is defined</p><p>Line#13 -14: A mock function for ‘getGPA’ is defined</p><p>Line#28: Verify getHello() method of AppController</p><p>Line#35: Verify getGpa of studentService has been called</p><p>Line#44: Verify the return value of getGpa is the same as the expected value</p><p>Now we will explore the Mock class approach in the case of <strong>student.service.spec.ts</strong> as provided below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62b254b374d7cc9d17a625ea8d368fa9/href">https://medium.com/media/62b254b374d7cc9d17a625ea8d368fa9/href</a></iframe><p>Line#1: The ‘Test’ class from ‘<a href="http://twitter.com/nestjs/testing">@nestjs/testing</a>’ provides a test execution context by mocking the full Nest runtime. It also provides hooks to help mock and overriding.</p><p>Line#5–13: Mock class</p><p>Line#23: The ‘createTestingModule’ method of ‘Test’ class takes a module metadata object and returns a TestingModule instance.</p><p>Line#24: The mock class implementation of ‘ApiService’ is provided to be used instead of the real implementation.</p><p>Line#25: The compile method of this object bootstraps a module with its dependencies and returns a module (Line#27) that is ready for testing.</p><p>Line#31: Verifying that the studentService object is defined.</p><p>Line#38: Verify that the received GPA is the same as the expected GPA</p><p>The next one is api.service.spec.ts, which is the test class for ApiService.</p><p>It also follows the same pattern as the above-explained classes. However, there is only one basic test that checks for the existence of the service instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a81036ca4854c9d2cef1e2b9a5a3f92a/href">https://medium.com/media/a81036ca4854c9d2cef1e2b9a5a3f92a/href</a></iframe><h3>3. Run unit test cases</h3><p>Now that we have three different test classes up and running, do an ‘npm test’ and make sure all of the test cases are successful. Here is the <a href="https://github.com/nishabe/studentGPA">complete source code</a> for this project in case you need it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*4s_hC4lSsQwHQbewgHxRUw.png" /></figure><h3>4. Add end to end test cases</h3><p>When you created the NestProject, the framework created a folder called ‘test’ and a file ‘app.e2e-spec.ts’ automatically. We will be adding code to this file. Drag and drop the folder ‘test’ so that it is under the ‘src’ folder. By default Jest searches for test files only under the ‘src’ folder.</p><p>Also, add below two properties (“collectCoverage”: true, “verbose”: true)to the Jest configuration section of package.json file as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89068780efd1dc5af308b92f07bcc9ec/href">https://medium.com/media/89068780efd1dc5af308b92f07bcc9ec/href</a></iframe><p>This will output greater details of the test in tabular format.</p><p>Now, let’s refresh a few concepts about the end to end testing.</p><p>Unlike unit testing, which focuses on individual modules and classes, end-to-end (e2e) testing covers the interaction of classes and modules, closer to the kind of interaction that end-users will have. Automated end-to-end tests help us ensure that the overall behavior of the system is correct.</p><p>In an E2E test, the idea is to also call your external services, but we will mock the HttpService for simplicity. This means we’ll call the APIService and we’ll use the Jest function spyOn to simulate our HTTP response. Nest makes it easy to use the Supertest library to simulate HTTP requests.</p><p>The overall code pattern of end to end test is similar to that of the unit testing class that we have seen before. There are some new concepts that we address soon. Below is the completed file for <strong>app.e2e-spec.ts</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/397c0363d485b58c28c3e484f3785045/href">https://medium.com/media/397c0363d485b58c28c3e484f3785045/href</a></iframe><p>Line#2: Importing ‘<a href="https://www.npmjs.com/package/supertest">Supertest</a>’. Supertest provides a high-level abstraction for testing HTTP. This helps to send requests to the server and then test the response.</p><p>Line#4: INestApplication, Interface defining the core NestApplication object.</p><p>Line#7: Importing AxiosResponse. An Axios response is a javascript object with several properties, including data, which contains the parsed response body.</p><p>Line#8: Importing ‘of’ from Rxjs. of() is used to return a fake response. It emits its parameters as single emissions immediately on subscription and then sends the complete notification. For more, check out this <a href="https://stackoverflow.com/questions/47889210/why-we-should-use-rxjs-of-function">discussion</a>.</p><p>Line#14–23: Importing dependencies, creating the test module, initializing it.</p><p>Line#26–35: Defining an expected response.</p><p>Line#36: Spying the implementation of the HTTP get method and providing it with a mock response.</p><p>Line#38: Simulate the invocation of HTTP GET call on the AppController, by specifying the routing path and query parameters. Also, an expectation is chained.</p><h3>5. Run all tests</h3><p>Assuming that everything so far is correct, while running the test, you should be presented with the below output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*KKRIQKu1uSzsyhTKgocRow.png" /></figure><p>Hope this has helped you in cracking the unit testing fundamentals of the NestJS app. Here is the <a href="https://github.com/nishabe/studentGPA">complete source code</a> for this project.</p><h4>References:</h4><p>H<a href="https://blog.theodo.com/2019/06/test-nestjs-with-jest-typescript/">ow to Test Your NestJS Application with Jest in 4 Steps</a></p><p><a href="https://blog.logrocket.com/unit-testing-nestjs-applications-with-jest/">Unit testing NestJS applications with Je</a>st</p><p><a href="https://www.carloscaballero.io/part-9-clock-in-out-system-testing-backend-unit-test-services/">Part 9. Testing: Backend Testing — Unit Testing — Services</a></p><p><a href="https://www.carloscaballero.io/part-10-clock-in-out-system-testing-backend-unit-test-controllers/">Part 10. Testing: Backend Testing — Unit Testing — Controllers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbe83da6408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NestJS + Serverless + Lambda + AWS — In shortest steps.]]></title>
            <link>https://nishabe.medium.com/nestjs-serverless-lambda-aws-in-shortest-steps-e914300faed5?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e914300faed5</guid>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 06:19:37 GMT</pubDate>
            <atom:updated>2021-01-07T17:28:23.454Z</atom:updated>
            <content:encoded><![CDATA[<h3>NestJS + Serverless + Lambda + AWS — In shortest steps.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*UIAQ8GrhzOQeumeYDM3Tuw.png" /></figure><p>Recently I wanted to try out deploying a NestJS project in AWS as a lambda using Serverless framework. This note is about what I learned, hoping that it may help others too.</p><p>Let&#39;s get familiarised with the terms used in the header.</p><p><a href="https://docs.nestjs.com/"><strong>NestJS</strong></a> — A framework for Node.js based server-side applications.</p><p>What problem does it solve? Architecture. Nest provides an out-of-the-box application architecture that allows developers to create highly testable, scalable, loosely coupled, and easily maintainable applications.</p><p><a href="https://www.serverless.com/"><strong>Serverless</strong></a> — A framework that helps you develop and deploy your AWS Lambda functions, along with the AWS infrastructure resources they require.</p><p>What problem does it solve? Complexity related to cloud deployment. It’s a CLI that offers structure, automation, and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of Functions and Events.</p><p>The goal is to create a basic NestJS app, use Serverless framework to wrap it as a Lambda, and then deploy the app into AWS.</p><p>On a high level there are three steps:</p><ol><li>Creating a basic NestJS app</li><li>Setup AWS account</li><li>Creating a Lambda out of the NestJS app</li><li>Deploying to AWS</li></ol><p>Below are the steps in detail:</p><h3>1. Creating a basic NestJS app</h3><p>Pre-requisites:</p><p><a href="https://nodejs.org/en/">NodeJS</a>, <a href="https://code.visualstudio.com/download">Visual Studio Code</a>, <a href="https://docs.nestjs.com/cli/overview">NestCLI</a>, <a href="https://www.serverless.com/framework/docs/providers/aws/guide/installation/">Serverless</a></p><p>Open Visual Studio Code, open terminal.</p><p>The next step is to create a project with the name that you use. Mine is ‘floaws’ (FirstLambdaOnAWS).</p><pre>$ nest new floaws</pre><p>When prompted package manager choice, select ‘npm’.</p><p>This will create a project in NestJS framework with a GET endpoint in the current directory. Open the newly created project in VS Code. You should something that looks like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*OLOkC8XEBXGxJTueYzCdjg.png" /></figure><p>Test the project by running it and verifying the GET response.</p><p>Terminal 1 in VS Code:</p><pre>nest start</pre><p>Terminal 2 in VS Code:</p><pre>curl http://localhost:3000</pre><p>The expected output in the terminal is:</p><pre>Hello World!</pre><h3>2. Setup AWS account</h3><p>If you do not have it already, <a href="https://portal.aws.amazon.com/billing/signup#/start">signup for an AWS account</a>.</p><p>Once an account is active, create a user with the AWS IAM service and get its access key and secret access key. When that information is available create a hidden folder called ‘.aws’ in your working directory with a file name ‘credentials’ and paste the below content. Save the file once done.</p><pre>[default]<br>aws_access_key_id = YOUR_ACCESS_KEY<br>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY</pre><p>In VS Code terminal of a Mac machine, the commands would be:</p><pre>mkdir .aws<br>cd .aws<br>touch credentials<br>open .</pre><h3>3. Creating a Lambda out of the NestJS app</h3><p>API Gateway creates a REST API in front of your lambdas. By default, each Serverless project generates a new API Gateway.</p><p>Serverless need an entry point to compile the NestJS app to a lambda function. This entry point will be a handler object exported in the file lambda.ts. Create the lambda.ts file in the src folder of your application as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*ZFsiRGwo00Hmrhk7UCGsRQ.png" /></figure><p>In the lambda.ts file copy and paste the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40fad04a6efa5353f91140a5f1150026/href">https://medium.com/media/40fad04a6efa5353f91140a5f1150026/href</a></iframe><p>Once the lambda entry point is created, configure Serverless to build this lambda. Create a file serverless.yaml at the root of your project with the content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28985cae64047d5725c1bc3dee3e9cbb/href">https://medium.com/media/28985cae64047d5725c1bc3dee3e9cbb/href</a></iframe><p>With this configuration, Serverless will create the Lambda function main that will serve all the routes and methods of the API.</p><p>The next step is to install a few dependencies:</p><p><strong>aws-serverless-express</strong> : This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js<br><strong>aws-lambda</strong>: AWS Lambda lets you run code without provisioning or managing servers.<br><strong>serverless-plugin-typescript</strong>: Serverless plugin for Typescript support that works out of the box without the need to install any other compiler or plugins.<br><strong>serverless-plugin-optimize</strong>: Plugin to transpile and minify your code<br><strong>serverless-offline plugin</strong>: Plugin to be able to test your app offline.</p><pre>npm install --save aws-serverless-express<br>npm install --save aws-lambda<br>npm install --save-dev serverless-plugin-typescript<br>npm install --save-dev serverless-plugin-optimize<br>npm install --save-dev serverless-offline plugin</pre><p>Once done, test the serverless configuration and the app by :</p><pre>sls offline start</pre><p>If you see a compile error related to ‘incremental’, set that property value as ‘false’ in tsconfig.json file.</p><p>If that succeeds, you should see a similar message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*mkZNETtBvXPZlDiF2bR2KA.png" /></figure><p>Stop running the app (Ctrl+C), and try deploying it by:</p><pre>sls deploy -v</pre><p>If everything goes well you should see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kTHZc8PCIkHzOiD0r2PclQ.png" /></figure><p>You can hit the URL provided in ‘ServiceEndPoint’the message and test the GET function.</p><p>Once you are happy with the results, do not forget to remove the cloud assets that were created.</p><p>The command to remove the lambda deployment is:</p><pre>serverless remove</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*daXA_2ntIivHy8Qreh41VQ.png" /></figure><p>Hope this helps!</p><p>Reference:</p><p><a href="https://blog.theodo.com/2019/06/deploy-a-nestjs-app-in-5-minutes-with-serverless-framework/">Deploy a NestJS App with Serverless Framework</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e914300faed5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Realtime Arithmetic Evaluation in iOS]]></title>
            <link>https://nishabe.medium.com/realtime-arithmetic-evaluation-in-ios-72f99e997892?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/72f99e997892</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 05:34:47 GMT</pubDate>
            <atom:updated>2020-04-22T17:35:36.969Z</atom:updated>
            <content:encoded><![CDATA[<p>Let me take a wild guess.</p><p>Once you got past the classic ‘Hello World!’, we all have done a project called ‘The Calculator’, regardless of the front end tech stack.</p><p>Recently, I came to know about a feature in an expense tracking app called <a href="https://apps.apple.com/us/app/spend-together/id1446549608">“Spend Together”</a>. When you add an expense, it keeps evaluating the operations on operands in realtime.</p><p>Here is a quick look at that feature:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*vPsRDEARu5ezdtIUbl8c9w.gif" /></figure><p>At first glance, nothing fancy, or so I thought.</p><p>The more I thought about it, the complexity began to unravel. I spend a weekend doing some research, refreshing the arithmetics, evaluating different options. And thus I discovered the powerful API called <a href="https://developer.apple.com/documentation/foundation/nsexpression">‘NSExpression’</a>. The most important aspect of NSExpression is that it keeps the evaluating going until your input is correct. If you give an incorrect input expression like ‘1+’, it will just crash on you.</p><p>At the end of two days, I came up with a working prototype that mimics this feature. Overall, time well spent with lots of great learning.</p><p>Here is a quick look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*D28ujsVdQYRwcomLW9c--A.gif" /></figure><p>Please feel free to check <a href="https://github.com/nishabe/expressions">the code here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72f99e997892" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accordion Implementation on Swift]]></title>
            <link>https://nishabe.medium.com/accordion-implementation-on-swift-48bc95acd9e5?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/48bc95acd9e5</guid>
            <category><![CDATA[accordian]]></category>
            <category><![CDATA[swift-5]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 05:04:09 GMT</pubDate>
            <atom:updated>2020-04-13T05:04:09.212Z</atom:updated>
            <content:encoded><![CDATA[<p>About twelve years back when I saw the accordion control as part of the ASP.net AJAX suite, my feeling was beyond surprise. The smooth animation, the expansion of a raw when you click on it, the intuitive behavior that comes with it, it was a game-changer in the Web UX. I don&#39;t think the original documentation is still alive but <a href="https://ajaxcontroltoolkit.devexpress.com/Accordion/Accordion.aspx">here is the closest one</a>.</p><p>It is pleasantly surprising to see that whatever problem this control solved before a decade is still relevant.</p><p>Here is a quick representation from the .NET world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*bhAntMllSe5toJR_70Q0wg.gif" /><figcaption>Accordion in ASP.net AJAX control suite</figcaption></figure><p>Back to 2020.</p><p>I spend some time on accordion implementation and found a few helpful resources. This video tutorial by Brian Voong (<a href="https://www.youtube.com/watch?v=Q8k9E1gQ_qg">Expandable and Collapsible Sections UITableView</a>) and this article by Stan Ostrovskiy (<a href="https://medium.com/ios-os-x-development/ios-how-to-build-a-table-view-with-collapsible-sections-96badf3387d0">How to build a Table View with Collapsible Sections</a>) was really great. Brian’s implementation was concise and simple. Stan’s implementation was on MVVM and addressed how to use custom classes with .xibs. Unfortunately, this is still in Swift 3.</p><p>So I decided to create a new sample implementation taking the best aspects of the two.</p><p>The result is a project, which is:</p><ul><li>Simple and concise</li><li>Uses custom classes and .xibs</li><li>Implemented in MVVM</li><li>In Swift 5</li></ul><p>Here is a quick look at how it looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*MlTxlLl7qzCLF7OwV2m4mg.gif" /></figure><p>Please feel free to see the <a href="https://github.com/nishabe/ExpandableTableRows">source code here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48bc95acd9e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Tab Switching in Safari]]></title>
            <link>https://nishabe.medium.com/auto-tab-switching-in-safari-e34cd531faf2?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e34cd531faf2</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[safari]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 20:18:45 GMT</pubDate>
            <atom:updated>2019-09-19T20:18:45.320Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is a neat trick I learned today.</p><p>It is about automatically cycling through different tabs in Safari browser.</p><p>In case you need to show different web pages in a monitor/display this will be helpful.</p><p>The solution is about writing an ‘Apple Script’ using the built-in script editor available in MacOS.</p><p>Open the editor, paste the below code and hit the ‘Run’ button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DncH3KdwcTxCY2sJhcuqAw.png" /></figure><pre><strong>tell</strong> <em>application</em> &quot;Safari&quot;</pre><pre><strong>repeat</strong></pre><pre><strong>repeat</strong> <strong>with</strong> i <strong>from</strong> (<strong>count</strong> <strong>of</strong> <em>tabs</em> <strong>of</strong> <em>window</em> 1) <strong>to</strong> 1 <strong>by</strong> -1</pre><pre><strong>set</strong> thisTab <strong>to</strong> <em>tab</em> i <strong>of</strong> <em>window</em> 1</pre><pre><strong>set</strong> current tab <strong>of</strong> <em>window</em> 1 <strong>to</strong> thisTab</pre><pre><strong>delay</strong> 5</pre><pre><strong>end</strong> <strong>repeat</strong></pre><pre><strong>end</strong> <strong>repeat</strong></pre><pre><strong>end</strong> <strong>tell</strong></pre><p>Just change the delay as needed.</p><p>Here is an example output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NJJpWac32KwbSuaU9k7ZuQ.gif" /></figure><h3>References:</h3><p><a href="https://apple.stackexchange.com/questions/39430/automatically-scan-cycle-through-safari-tabs?newreg=f0394202e46a4e6da6d933fc5668dab2">Link 1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e34cd531faf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to delete an SSL cert from the Java trust store (MacOS)?]]></title>
            <link>https://nishabe.medium.com/how-to-delete-an-ssl-cert-from-the-java-trust-store-macos-afaafca27f92?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/afaafca27f92</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 14:00:43 GMT</pubDate>
            <atom:updated>2019-08-29T14:00:43.325Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Open terminal</li><li>Go the folder where <strong>cacerts</strong> resides. For example the location of <strong>cacerts </strong>in MacOS Mohave is:</li></ol><pre>/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/jre/lib/security</pre><p>3. The below command list all the certs added to the truststore. Make sure you see the cert to be removed is in the list.</p><pre>keytool -list -keystore cacerts</pre><p>When prompted to ‘Enter keystore password:’, enter the password. The default password is ‘changeit’.</p><p>4. Assuming that the cert is listed, execute the below command.</p><pre>sudo keytool -delete -alias certificate_alias_here -keystore cacerts</pre><p>5. Enter the admin password.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afaafca27f92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to uninstall Jenkins from Mac OS?]]></title>
            <link>https://nishabe.medium.com/how-to-uninstall-jenkins-from-mac-os-974a9d47b14e?source=rss-2d938a3ec7e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/974a9d47b14e</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[homebrew]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[nish abe]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 17:35:59 GMT</pubDate>
            <atom:updated>2019-07-19T17:35:59.384Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have installed Jenkins using homebrew and if you want to uninstall it completely, this is how you do it:</p><pre>brew uninstall jenkins --force<br>brew cleanup</pre><p>If you have installed it as a package from Jenkins.io follow <a href="https://medium.com/@anoopm6/how-to-uninstall-jenkins-from-mac-5a40b1e6bab6">this post</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=974a9d47b14e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>