<?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: Akram Saouri</title>
    <description>The latest articles on Forem by Akram Saouri (@akram).</description>
    <link>https://forem.com/akram</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%2F19894%2Fa61b8080-cd39-4a63-96e0-9d44c430651e.jpg</url>
      <title>Forem: Akram Saouri</title>
      <link>https://forem.com/akram</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/akram"/>
    <language>en</language>
    <item>
      <title>Using Netlify functions to host a GraphQL API with a React frontend</title>
      <dc:creator>Akram Saouri</dc:creator>
      <pubDate>Tue, 15 Oct 2019 20:18:50 +0000</pubDate>
      <link>https://forem.com/akram/how-i-used-netlify-functions-to-host-my-graphql-api-with-my-react-frontend-27j1</link>
      <guid>https://forem.com/akram/how-i-used-netlify-functions-to-host-my-graphql-api-with-my-react-frontend-27j1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This quick demo assumes you’re already familiar with Netlify as a deployment service, GraphQL as an API technology and React. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The starting point was a normal React project created with &lt;code&gt;create-react-app&lt;/code&gt;   then deployed on Netlify (you know…the usual)&lt;br&gt;&lt;br&gt;
Then I arrived to the point where I found out I needed an API to do some backend-related stuff, I (innocently) reached out to create a new repository, wrote some GraphQL resolvers/mutations, committed the whole thing but just when I was looking for a &lt;em&gt;cheap&lt;/em&gt; vps to host it in, I stopped for a second then said to my self: why not do it on Netlify itself?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Narrator: he did not regret it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The process was as straightforward as this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;I’ve started by &lt;em&gt;completely&lt;/em&gt; moving the backend files from their separate repo to inside &lt;code&gt;src/&lt;/code&gt; folder in the frontend repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R_LQGBmK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://api.monosnap.com/file/download%3Fid%3Dj5J4qHp6gAls2mbhHM7ZCJ1zFRitCt" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R_LQGBmK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://api.monosnap.com/file/download%3Fid%3Dj5J4qHp6gAls2mbhHM7ZCJ1zFRitCt" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then I’ve added  &lt;a href="https://github.com/netlify/netlify-lambda"&gt;netlify-lambda&lt;/a&gt; as a dev dependency to the project; this is a tool created by the netlify team and provides a runtime for lambda functions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I did not have a &lt;code&gt;netlify.toml&lt;/code&gt; file at the time so I created one, and updated the content with this:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[build]
  command = "yarn build" # the command you run to build this file
  functions = "built-lambda" # netlify-lambda builds to this folder AND Netlify reads functions from here
  publish = "build" # create-react-app builds to this folder, Netlify should serve all these files statically

// This helps the `netfliy-lambda` do its job and helps Netlify figuring out where to look for your functions when deployed. 
// Note: the `functions` field will probably be different in your project depending on where you decided to put the GraphQL functions
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The I’ve added two new scripts to my &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;&lt;br&gt;
        - &lt;code&gt;”start:lambda”:”netlify-lambda serve src/lambda”&lt;/code&gt;&lt;br&gt;&lt;br&gt;
        - &lt;code&gt;”build:lambda”:”netlify-lambda build src/lambda”&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;before going all lambda crazy, the backend repository was using a normal &lt;a href="https://github.com/apollographql/apollo-server"&gt;apollo-server&lt;/a&gt; but now I needed to find a lambda compatible one, luckily &lt;a href="https://www.npmjs.com/package/apollo-server-lambda"&gt;apollo-server-lambda &lt;/a&gt; does exactly this and &lt;em&gt;barely&lt;/em&gt; required any changes on the existing files, the &lt;code&gt;graphql.js&lt;/code&gt; looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-server-lambda&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;typeDefs&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./lib/typeDefs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;resolvers&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./lib/resolvers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newApolloServer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="nx"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;playground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;introspection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createHandler&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The last piece now was to wire the GraphQl client with the Netlify function: &lt;br&gt;&lt;br&gt;
On the frontend, I’m working with &lt;code&gt;urql&lt;/code&gt; so I had to update the client initialisation to this:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
       &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:9000/.netlify/functions/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
       &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/.netlify/functions/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
   &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;http://localhost:9000/.netlify/functions/graphql&lt;/code&gt; URL is the default one when running &lt;code&gt;npm run start:lambda&lt;/code&gt; locally but when deploying to Netlify the functions are hosted on the same domain hence the check.   &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: This code is still valid for &lt;em&gt;your&lt;/em&gt;  favorite GraphQL client too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now once I published  these new changes to Netlify, it detected that I’ve added a new function and did its magic:&lt;br&gt;&lt;br&gt;
  &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PmVpjWMr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://api.monosnap.com/file/download%3Fid%3Dds8hZMWnKgZWO1alZSEvM4EPl5Wyc4" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PmVpjWMr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://api.monosnap.com/file/download%3Fid%3Dds8hZMWnKgZWO1alZSEvM4EPl5Wyc4" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Couple of notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When working with databases, the standard approach of starting the database with the server does not work in this case since the lambda function is given a limited time to run on every request and will be shut down after the request is resolved, the solution is to open a database connection on every incoming request and cache it the between requests. I was able to do that (with &lt;code&gt;mongdb&lt;/code&gt; in my case) using something like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cachedDb&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cachedDb&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;cachedDb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serverConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isConnected&lt;/span&gt;&lt;span class="p"&gt;()){&lt;/span&gt;
        &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cachedDb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connectDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;cachedDb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can simulate a full working Netlify runtime locally using their &lt;a href="https://www.netlify.com/products/dev/"&gt;Netlify Dev | Netlify&lt;/a&gt; tool, this comes handy when you want to debug you full wired app locally.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Relevant Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Docs for Netlify functions:  &lt;a href="https://www.netlify.com/docs/functions/"&gt;https://www.netlify.com/docs/functions/&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; Netlify lambda: &lt;a href="https://github.com/netlify/netlify-lambda"&gt;https://github.com/netlify/netlify-lambda&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Apollo server lambda: &lt;a href="https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-lambda"&gt;apollo-server/packages/apollo-server-lambda at master · apollographql/apollo-server&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Netlify dev:  &lt;a href="https://www.netlify.com/products/dev/"&gt;Netlify Dev | Netlify&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>netlify</category>
      <category>graphql</category>
      <category>react</category>
    </item>
    <item>
      <title>Common gotchas when working with Electron.js</title>
      <dc:creator>Akram Saouri</dc:creator>
      <pubDate>Sun, 31 Mar 2019 18:58:19 +0000</pubDate>
      <link>https://forem.com/akram/common-gotchas-when-working-with-electron-js-4m7n</link>
      <guid>https://forem.com/akram/common-gotchas-when-working-with-electron-js-4m7n</guid>
      <description>&lt;h1&gt;
  
  
  Common gotchas when working with Electron.js
&lt;/h1&gt;

&lt;p&gt;So I had the chance to play with Electron.js past weeks building dummy applications and wanted to share my small experience with it when building cross platform desktop apps. &lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;An Electron application has two processes:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The main process: there is always one and only one main process per application responsible for creating web pages, picture it like a server-client architecture with the main process being the server in this case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The render process: representing the web pages (client) created by the main process and running on &lt;a href="https://dev.chromium.org/developers/design-documents/multi-process-architecture"&gt;chromium multi-process architecture&lt;/a&gt;.    &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recommend &lt;a href="https://electronjs.org/docs/tutorial/application-architecture"&gt;the official doc&lt;/a&gt; for reading in-depth about the architecture.  &lt;/p&gt;

&lt;h3&gt;
  
  
  IPC
&lt;/h3&gt;

&lt;p&gt;IPC (Short for &lt;code&gt;Inter Process Communication&lt;/code&gt;) is a protocol used on Electron apps for enabling communication between its processes (Main and Renderer)&lt;br&gt;
Electron makes this possible by providing two modules: &lt;a href="https://electronjs.org/docs/api/ipc-main"&gt;ipcMain&lt;/a&gt; for the main process and &lt;a href="https://electronjs.org/docs/api/ipc-renderer"&gt;ipcRenderer&lt;/a&gt; for the renderer process(es), both these modules are based on &lt;a href="https://nodejs.org/api/events.html#events_class_eventemitter"&gt;EventEmitter&lt;/a&gt; and provide functions for listening on and emitting events. &lt;/p&gt;

&lt;p&gt;A basic example for pinging a renderer process from a main process and listening for a response can be like the following:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in the main process&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ipcMain&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'electron'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;myWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;webContents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'event_from_main'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ping_from_main'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;ipcMain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'event_from_renderer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ping_from_renderer&lt;/span&gt;
    &lt;span class="c1"&gt;// we can use event.sender.send to reply to event &lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// in the renderer process&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ipcRenderer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'electron'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;ipcRenderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'event_from_main'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ping_from_main&lt;/span&gt;
    &lt;span class="nx"&gt;ipcRenderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'event_from_renderer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ping_from_render'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Data persistence
&lt;/h2&gt;

&lt;p&gt;Electron.js as a &lt;em&gt;framework&lt;/em&gt; isn’t opinionated when it comes to how to store your data, it’s up to you and your needs to choose a database, be it either a local one (localStorage, indexedDB) or go big like Postgres or MongoDB (in general as long as there is a Node.js adapter for it, you’re welcome to use it) &lt;br&gt;
I personally always find my self reaching out for &lt;a href="https://github.com/typicode/lowdb/"&gt;lowdb)&lt;/a&gt; in small or prototype projects since it’s easy to use (lodash syntax like) and really gives you the flexibility afterwards to migrate to something bigger once you figure out what you &lt;em&gt;really&lt;/em&gt; need.&lt;/p&gt;

&lt;h2&gt;
  
  
  UI and Styles
&lt;/h2&gt;

&lt;p&gt;Unlike other desktop apps toolkits, views/pages in an electron application are just regular html files, this means you can bring your favorite styling friends to the party (sass, less, css grid, svgs etc…)&lt;br&gt;
Also there are some boilerplates out there for using React, Vue and other UI libs with Electron. &lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://twitter.com/sindresorhus"&gt;@sindresorhus&lt;/a&gt; built &lt;a href="https://github.com/sindresorhus?utf8=%E2%9C%93&amp;amp;tab=repositories&amp;amp;q=electron&amp;amp;type=source&amp;amp;language="&gt;tons&lt;/a&gt; of utilities that can help your development workflows with Electron, my favourite ones are  &lt;a href="https://github.com/sindresorhus/electron-util"&gt;electron-util&lt;/a&gt;,  &lt;a href="https://github.com/sindresorhus/run-electron"&gt;run-electron&lt;/a&gt; and  &lt;a href="https://github.com/sindresorhus/electron-context-menu"&gt;electron-context-menu&lt;/a&gt;.&lt;br&gt;
Also to package and build your application, I recommend &lt;a href="https://www.npmjs.com/package/electron-builder"&gt;electron-builder&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://electronjs.org/docs"&gt;https://electronjs.org/docs&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://github.com/sindresorhus/awesome-electron"&gt;https://github.com/sindresorhus/awesome-electron&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>electron</category>
      <category>javascript</category>
      <category>electronjs</category>
    </item>
    <item>
      <title>Web Assembly</title>
      <dc:creator>Akram Saouri</dc:creator>
      <pubDate>Sun, 01 Jul 2018 13:43:09 +0000</pubDate>
      <link>https://forem.com/akram/web-assembly-1egk</link>
      <guid>https://forem.com/akram/web-assembly-1egk</guid>
      <description>&lt;h2&gt;
  
  
  Web Assembly, the what, the why and the how
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The what
&lt;/h3&gt;

&lt;p&gt;Web assembly also called Wasm is an efficient, low level byte code for the web, the efficient part means that it’s not only fast to deliver to the client browser but also fast to execute, it’s characterised by being a safe and a portable language meaning that you won’t have to deal with memory overflows and issues like that and the generated machine code can be executed on any platform and adapts to its architecture.   &lt;/p&gt;

&lt;h3&gt;
  
  
  The why
&lt;/h3&gt;

&lt;p&gt;W3C created Wasm for two major reasons, the first one as a complementary solution to JavaScript especially for applications with heavily CPU/GPU computations (think games, encryption, image or video optimisation and editing etc..), and the second one is to enable developers to write their web apps in other languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  The how
&lt;/h3&gt;

&lt;p&gt;Wasm is defined as a compilation target meaning that in a normal scenario you would write your program in some other languages (currently supporting C/C++ and Rust) and then compile it to a web assembly executable file. &lt;br&gt;
The generated binary file can be injected to your web application and the browser parsing the file will skip all the steps usually run when parsing JS files and go straight to generating the machine code for the platform you’re using, and this is happening because Wasm is already optimised and has static types informations. &lt;/p&gt;

&lt;h3&gt;
  
  
  Getting started
&lt;/h3&gt;

&lt;p&gt;To play around with Wasm, I recommend  &lt;a href="https://webassembly.studio/"&gt;https://webassembly.studio/&lt;/a&gt;  which is an awesome web editor allowing devs to experiment with Wasm and write web assembly based projects. &lt;br&gt;
There is also &lt;a href="https://mbebenita.github.io/WasmExplorer/"&gt;https://mbebenita.github.io/WasmExplorer/&lt;/a&gt; which is basically a tool used to translate C/C++ code to Wasm binary code and even see the linear assembly byte-code generated by the browser (this is basically the human readable intermediary representation for the machine code)&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
