<?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 Sven Adlung on Medium]]></title>
        <description><![CDATA[Stories by Sven Adlung on Medium]]></description>
        <link>https://medium.com/@sven.adlung?source=rss-49fd17b81ac3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PwPgQvEdxxhxBQ7HOSXBKA.jpeg</url>
            <title>Stories by Sven Adlung on Medium</title>
            <link>https://medium.com/@sven.adlung?source=rss-49fd17b81ac3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 08:06:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sven.adlung/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[ Develop and deploy a Node.js microservice to enhance the capabilities of React and Firebase]]></title>
            <link>https://medium.com/ueberdosis/develop-and-deploy-a-node-js-microservice-to-enhance-the-capabilities-of-react-and-firebase-bdc595848050?source=rss-49fd17b81ac3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc595848050</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sven Adlung]]></dc:creator>
            <pubDate>Mon, 15 Jan 2018 15:36:15 GMT</pubDate>
            <atom:updated>2018-01-15T15:36:15.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 How to rapidly develop and deploy a Node.js microservice to enhance the capabilities of React and Firebase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SN-4PFDbkKl4ZFbpLQACTQ.jpeg" /></figure><p>In times of JavaScript-based frontend applications driven by frameworks like <a href="https://reactjs.org/">React</a> and cloud-hosted databases like <a href="https://firebase.google.com/">Firebase</a> in the backend, some functions (usually done on a server) are lacking quickly, once the application breaks out of bounds. There are situations where you want to extend the backend capabilities: use cronjobs or send e-mails without doing that by triggering external webservices from the client-side-code and probably share secret API keys with the world.</p><blockquote>What’s missing is an easy and rapid way to develop and deploy simple microservices that are built as a layer between frontend app and cloud-based backend.</blockquote><p><strong>Since 2017, there is an open Beta for </strong><a href="https://firebase.google.com/docs/functions/"><strong>Firebase Cloud Functions</strong></a><strong> which is reliable just for these challenges. Unfortunately, some things are only available when switching to the Blaze plan (for example perform HTTP requests to external services from a Cloud Function). Let’s find another way.</strong></p><p>A common way would be to create a small PHP application with a framework like <a href="https://laravel.com/">Laravel</a> ( 💜 ) or even smaller with <a href="https://lumen.laravel.com/">Lumen</a> i.e. Or just use Vanilla PHP. The next step is getting a server to run on this project. Why not put everything into a <a href="https://www.docker.com/">docker</a> container … and anyways, what about the deployment? Let’s set up a <a href="https://jenkins-ci.org/">Jenkins</a> deployment to get everything automated.</p><h3>⏰ ⏰ ⏰ ⏰ ⏰ ⏰ ⏰</h3><p>Phew! You see, things become huge fast! Don’t get me wrong — usually that’s the way I would probably go. But sometimes it’s just too much...</p><h3>Node.js microservice in the middle</h3><p>Depending on the case, <a href="https://nodejs.org/">Node.js</a> might be enough to fulfil the backend needs. And anyways, you are using JavaScript in the frontend, why not stick with it in the backend?</p><p>This article won’t dig into details, the advantages or disadvantages of <br>Node.js — it will just give you a few small examples for our previous points concerning React and Firebase.</p><h4>Start with a clean Node.js project</h4><p>Create a new folder (mkdir example-app), jump into it (cd example-app) and create a new project (yarn init). Just follow the points and enter your preferences:</p><pre>$ yarn init<br>yarn init v0.27.5<br>question name (example-app):<br>question version (1.0.0):<br>question description:<br>question entry point (index.js):<br>question repository url:<br>question author:<br>question license (MIT):<br>success Saved package.json<br>Done in 8.91s.</pre><p>I prefer adding <em>express</em> to communicate with the app (yarn add express). Next we create a <em>server.js</em> (touch server.js). This will be our entry point.</p><p>Add some boilerplate code to get everything running:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/beb93dc009e7de95cd4722c420d22d95/href">https://medium.com/media/beb93dc009e7de95cd4722c420d22d95/href</a></iframe><p>That’s pretty much it 🎉. Start it with yarn start and open <a href="http://localhost:3000/">localhost:3000</a> in your browser.</p><h4><strong>Interact with Firebase (</strong><a href="https://firebase.google.com/docs/reference/admin/node/"><strong>Firebase Admin SDK</strong></a><strong>)</strong></h4><p>To get and set data from firebase, you just need to add the <em>firebase-admin</em> package (yarn add firebase-admin).</p><p>To connect to firebase, you need to get a so called <em>service account key</em>. When doing so, just follow the instructions given by the <a href="https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app">firebase docs</a>:</p><ol><li>Navigate to the <a href="https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk"><strong>Service Accounts</strong></a> tab in your project’s settings page.</li><li>Select your Firebase project. […]</li><li>Click the <strong>Generate New Private Key</strong> button at the bottom of the <strong>Firebase Admin SDK</strong> section of the <strong>Service Accounts</strong> tab.</li></ol><p>Let’s add everything to our <em>server.js.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98b7c2baadbf611e75dd2cf7f728ba08/href">https://medium.com/media/98b7c2baadbf611e75dd2cf7f728ba08/href</a></iframe><p>As you can see I am using some environment variables. More about this later ...</p><p>With this done, you can connect to your Firebase database and do several things, even things you can’t achieve in the Firebase Console itself. In our case we needed to retrieve some user informations (by a given user uid) and process them.</p><p>What’s next? Well, we also needed to do some same action periodically every night. Let’s add a cronjob for that.</p><h4><strong>Automate tasks with cron</strong></h4><p>This is done easily with the <em>node-cron</em> package. So run yarn add node-cron and implement it to the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3666e860ad46bdc036404ec60891ade/href">https://medium.com/media/f3666e860ad46bdc036404ec60891ade/href</a></iframe><p>What else could be useful? Maybe send an e-mail (to a given user at a specific time … 🙃)!</p><h4>Send an e-mail through an external SMTP service with Node.js</h4><p>Here we use a package called <em>nodemailer</em> (yarn add nodemailer):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1a3a299ff7d448956c8f2b17ea9120f/href">https://medium.com/media/f1a3a299ff7d448956c8f2b17ea9120f/href</a></iframe><p>Just combine everything and you can do things you usually can’t do with React and Firebase alone (except using firebase cloud functions, see the info above).</p><p>Pretty awesome, isn’t it? But how do we get this running online? Let’s take a look at ZEIT now.</p><h3>ZEIT now — “Realtime global deployments”</h3><p>Probably you already have heard of <a href="https://zeit.co/now">ZEIT now</a>. Let’s see what <em>ZEIT</em> says about their own product:</p><blockquote>now allows you to take your JavaScript (Node.js) or Docker powered websites, applications and services to the cloud with ease, speed and reliability.</blockquote><p>Wouldn’t it be great to get all of the things online with just one command in the terminal? Since all dependencies are already set in <em>package.json </em>there is no further need of configuration to get the project running in the cloud.</p><p>How about just type</p><pre><em>$ now</em></pre><p>in the project root directory and the rest is done by the <em>now cli</em>? Seriously, it’s that easy!</p><p>First install <em>now</em> globally:</p><pre>yarn global add now</pre><p>Now you can run the cli of <em>now</em>! First time running, it will ask you to create an account and send you an e-mail to verify. It’s done within seconds. <br>Promise🤞.</p><p>And this is how a deployment looks like:</p><pre>$ now<br>&gt; Deploying ~/Websites/example-app under xxx@example.com<br>&gt; Using Node.js 8.9.3 (default)<br>&gt; Ready! <a href="https://example-app-pjigngjmxx.now.sh/">https://example-app-pjigngjmxx.now.sh</a> (copied to clipboard) [1s]<br>&gt; You (xxx@example.com) are on the OSS plan. Your code and logs will be made public.<br>&gt; NOTE: You can use `now --public` to skip this prompt<br>&gt; Initializing…<br>&gt; Building<br>&gt; ▲ npm install<br>&gt; ✓ Using &quot;yarn.lock&quot;<br>&gt; ⧗ Installing 1 main dependency…<br>&gt; ✓ Installed 48 modules [4s]<br>&gt; ▲ npm start<br>&gt; &gt; example-app@1.0.0 start /home/nowuser/src<br>&gt; &gt; node server.js<br>&gt; Server started on: 3000<br>&gt; Deployment complete!</pre><p>As you can see our app is running and we can open it on:</p><pre><a href="https://example-app-pjigngjmxx.now.sh/">https://example-app-pjigngjmxx.now.sh</a></pre><p>If you are using the free plan (OSS) you can skip the prompt of the <em>now-cli</em> telling you, that your code will be made public by adding --public.</p><p><strong>Keep in mind that in free plan your whole code is available for people that have knowledge of the address. Just add </strong><strong>/_src and you can see your code (and everyone else does).</strong></p><p>For me personally there is nothing bad about it but obviously I don’t want my sensitive data to be public to everyone. That’s why we are using environment variables we work with. In the previous code you might have recognized code like process.env.DATABASE_URL. DATABASE_URL is sth. that we keep in our .env file (DATABASE_URL=&quot;https://example-app.firebaseio.com&quot;). With this command you tell <em>now</em> to use it:</p><pre>now --dotenv</pre><blockquote><strong><em>Note: Don’t forget to add a </em>.gitignore<em> with </em></strong><strong><em>.env in it so </em>now<em> doesn’t deploy it!</em></strong></blockquote><p>Maybe you have noticed that <em>now</em> adds random characters to each instance to create unique addresses. <strong>What about having a static address that is not changing everytime?</strong> Well, we can achieve this by giving the app an <em>alias</em>. We do this by adding a <em>now.json</em> file to the root and specify an alias:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a5e80eb2121f4ce7f42954e2c2b3027/href">https://medium.com/media/0a5e80eb2121f4ce7f42954e2c2b3027/href</a></iframe><p>With now <strong><em>$ now alias</em></strong> we can easily assign it:</p><pre>$ now alias<br>&gt; Assigning alias example-app to deployment...<br>&gt; Success! example-app.now.sh now points to example-app-pjigngjmxx.now.sh! [6s]</pre><p>We can even combine everything: <strong><em>$ now --dotenv --public &amp;&amp; now alias</em></strong></p><p>Don’t forget there is a limit of 3 max. instances in the free plan of <em>now</em>. In our case that’s fine. The only problem is that after 3 instances, the cli is warning and we manually have to remove at least one instance to go on deploying:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*iGOtpFmYIaDdsg57zF1s1g.png" /></figure><p>Removing instances can be done using <br><strong><em>$ now rm example-app-pjignghmxx</em></strong></p><p>But as you can see, it needs the instance key which you can retrieve with <br><strong><em>$ now ls</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1vdU_oERmaR2dhJBXb-Rw.png" /></figure><p>This is where <em>now-clear</em> by Tal Bereznitskey comes into play. Just install with <strong><em>$ yarn global add now-clear</em></strong>, get your <a href="https://zeit.co/account/tokens"><em>now</em> token</a> and run it with your deployment name: <strong><em>$ now-clear -n example-app -t YOUR_TOKEN</em></strong></p><p><a href="https://github.com/berzniz/now-clear">berzniz/now-clear</a></p><p>If you don’t want to publish your sources, the quota is too low or you need individual domains, just take a look at the other <a href="https://zeit.co/pricing">plans of ZEIT now</a>.</p><p>Altogether, this is our deployment command:</p><pre>$ now-clear -n example-app -t OUR_TOKEN &amp;&amp; now --dotenv --public &amp;&amp; now alias</pre><p>This performs:</p><ol><li>Clear previous instances (needed for the free plan, max. 3 instances)</li><li>Deploy with environment variables and skip the prompt</li><li>Link deployed instance with alias</li></ol><p>We will shortly create a terminal alias or put everything in a bash script to keep things simple.</p><h4>Summary</h4><p>In our case this setup worked out really smoothly and fast. Which doesn’t mean that’s the one way to go. Maybe it’s not flexible enough for all situations but we just needed a tiny helping layer between the SPA and a cloud database without having a huge tech stack. The deployment is super easy and saved us a lot of time.</p><p>If you liked the article, feel free to give us some claps 👋 <br>Do you have any comments or suggestions? Please don’t hesitate and leave us a message.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc595848050" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ueberdosis/develop-and-deploy-a-node-js-microservice-to-enhance-the-capabilities-of-react-and-firebase-bdc595848050">🚀 Develop and deploy a Node.js microservice to enhance the capabilities of React and Firebase</a> was originally published in <a href="https://medium.com/ueberdosis">überdosis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>