<?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 Sankait on Medium]]></title>
        <description><![CDATA[Stories by Sankait on Medium]]></description>
        <link>https://medium.com/@sankait36?source=rss-66550011859e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*6_vmUZCshjgAoo8UMyWh1w.jpeg</url>
            <title>Stories by Sankait on Medium</title>
            <link>https://medium.com/@sankait36?source=rss-66550011859e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:59:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sankait36/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[Setting up a simple electron update server]]></title>
            <link>https://medium.com/@sankait36/setting-up-a-simple-electron-update-server-e544159811f6?source=rss-66550011859e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e544159811f6</guid>
            <category><![CDATA[auto-update]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[electron]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[desktop]]></category>
            <dc:creator><![CDATA[Sankait]]></dc:creator>
            <pubDate>Mon, 14 Oct 2019 20:13:54 GMT</pubDate>
            <atom:updated>2019-10-15T15:26:46.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0qtrCiGontQuFzgO6BbtMQ.png" /></figure><p>If you are working with electron, you may find yourself needing to push new changes to your deployed app. In order to achieve that, you need to set up a server that holds the update artifacts so that electron can listen to it and update when a new version is published.</p><p>This tutorial will show how to make your own simple update server. This server has two parts: A backend REST server that can handle file uploads, and a static file server that exposes those files. This example was run on an Ubuntu 18.04 EC2 instance (t2.micro, 30 GB EBS storage).</p><p>First of all, make sure to install the dependencies</p><ul><li><a href="https://github.com/nvm-sh/nvm">Node</a> — Preferably Node 10+, install via nvm</li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04">Docker</a> — This will be used to spin up an apache server that will act as our static file server and expose the update artifacts.</li></ul><h3><strong>Creating the REST server</strong></h3><p>Create a new folder for the app and set up the project. Use either yarn or npm. Open the terminal and run</p><pre>npm i -g yarn<br>mkdir simple-update-server<br>cd simple-update-server<br>yarn init  # Make the necessary configuration or leave as default</pre><p>Add the following packages as dependencies</p><pre>yarn add express express-fileupload morgan</pre><p>In your package.json file, add scripts to start the server</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a27a0f0da34cff3d03d15ba8f0d532a8/href">https://medium.com/media/a27a0f0da34cff3d03d15ba8f0d532a8/href</a></iframe><p>The prestart hook creates a files/ directory in your project and make the current user the owner of that folder. Change ubuntu to your current user.</p><p>Create a file called config.js. This allows us to create a custom auth secret to pass as a header to the REST server. This is entirely optional</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e50d8338b2312f88c62194eafd601d92/href">https://medium.com/media/e50d8338b2312f88c62194eafd601d92/href</a></iframe><p>Finally, create the index.js file for the main logic of the server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d925439a896085fa98f22dbddcc9e4b/href">https://medium.com/media/6d925439a896085fa98f22dbddcc9e4b/href</a></iframe><p>Run the server with yarn start.You should see the files/ directory created automatically.</p><p>The server exposes 2 endpoints. /ping checks if the server is up and running and /upload takes in the files and moves them to the files/ directory.</p><p>Test out the API: You can use Postman (with form-data) or run a cURL command as follows. You can add as many files as you like, just add more -F flags. You should see the files uploaded to the files/ directory if successful.</p><pre>curl -X POST -H &#39;Authorization: &lt;Your Auth Token&gt;&#39; -F &#39;File=@&lt;path/to/file1&gt;&#39; -F &#39;File=@&lt;path/to/file2&gt; <a href="http://3.15.23.82:3030/upload">http://&lt;Your server IP&gt;:3030/upload</a></pre><h3>Creating the Static file server</h3><p>We can create an Apache container using docker, and make the files/ directory from earlier as the bind mount. In the terminal run the following command.</p><pre>docker run -dit --name simple-update-file-server -p 5080:80 -v ~/simple-update-server/files:/usr/local/apache2/htdocs/:ro httpd:2.4</pre><p>The -v flag mounts the directory source:destination. The :ro after destination makes it a read-only mount. Make sure to change the source directory to wherever your project is located. The origin port number and the container name can be set to your preference.</p><p>Navigate to &lt;Your IP&gt;:5080 and make sure your files are there. If you see them, then the server is all done!</p><h3>Configuring Electron</h3><p>Now that the server is set up, we need to make some changes in the Electron client to listen to this server for updates. This example will use electron-builder and electron-updater .</p><p>We need to set the <a href="https://www.electron.build/configuration/publish#genericserveroptions">generic server options</a> for electron-builder so electron can listen for updates here. In your app’s package.json, set the following inside the build property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e325e26ef61546e30d1f3ae6923726dc/href">https://medium.com/media/e325e26ef61546e30d1f3ae6923726dc/href</a></iframe><p>In your electron.js file, add the following to handle the update-downloaded event. You can handle the other events as well, defined <a href="https://www.electron.build/auto-update#events">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/deb37dc945c6ef96939325c9eb7842f6/href">https://medium.com/media/deb37dc945c6ef96939325c9eb7842f6/href</a></iframe><p>In your app.on(&#39;ready&#39;... event, make sure you call autoUpdater.checkForUpdates()</p><h3>Testing it all</h3><ol><li>Publish the app with electron-builder</li><li>Upload the artifacts from the dist/ folder(besides the *-unpacked folders and the builder-effective-config.yaml file)</li><li>Download the application via the file server</li><li>Run the application</li><li>Update the package.json for the client application, and repeat 1–2 again</li><li>Run the application, you should now see an update prompt.</li></ol><p>If you successfully see the update prompt, your update server is complete!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e544159811f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>