<?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>DEV Community: Potch</title>
    <description>The latest articles on DEV Community by Potch (@potch).</description>
    <link>https://dev.to/potch</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%2F151696%2Fe10e6dff-7dc6-4d3c-a946-be60c9b61e89.png</url>
      <title>DEV Community: Potch</title>
      <link>https://dev.to/potch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/potch"/>
    <language>en</language>
    <item>
      <title>Glitching in a Material World</title>
      <dc:creator>Potch</dc:creator>
      <pubDate>Mon, 11 May 2020 16:32:51 +0000</pubDate>
      <link>https://dev.to/glitch/glitching-in-a-material-world-3fkm</link>
      <guid>https://dev.to/glitch/glitching-in-a-material-world-3fkm</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/15HpQBvvHS8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Last fall, I was fortunate to be able to attend the Chrome Developer Summit in San Francisco. In addition to all the sessions, there was a demo and exhibition floor showing off all sorts of web tech. The &lt;a href="https://material.io/" rel="noopener noreferrer"&gt;Material Design team&lt;/a&gt; was there, showing off a booth where attendees could snap a photo of themselves and use the colors from the image to customize their own version of the Material Design theme. It was a great example of a &lt;a href="https://glitch.com/~material-theme-generator?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;live demo&lt;/a&gt; that draws people in and leaves them with a digital souvenir that they'll want to tinker with later. Of course, I was also excited to see that it was powered by &lt;a href="https://glitch.com?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;Glitch&lt;/a&gt;!&lt;/p&gt;


&lt;div class="glitch-embed-wrap"&gt;
  &lt;iframe src="https://glitch.com/embed/#!/embed/material-theme-generator?previewSize=100&amp;amp;path=index.html" alt="material-theme-generator on glitch"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;I'm consistently impressed with how the Material Design team has embraced and pushed the capabilities of Glitch on &lt;a href="http://glitch.com/@material?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;their team page&lt;/a&gt;, so I was thrilled to help them figure out how to make one small aspect of their theme generator work.&lt;/p&gt;

&lt;p&gt;The challenge was this—let a booth visitor tweak the settings to see what the design system can do, and then "save" their changes to their own copy so they can get back to it later and keep playing! We could save a user's changes to the project filesystem, but then multiple users would be overwriting each other at the booth. The solution takes advantage of the ability to send custom environment variables to a project remix when it's created.&lt;/p&gt;

&lt;p&gt;For example, if you wanted to remix &lt;code&gt;hello-express&lt;/code&gt; and set the environment variable SECRET when making a remix, you can go to the following URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://glitch.com/edit/#!/remix/hello-express?SECRET=message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once the remix is finished, you'll have your own copy of &lt;code&gt;hello-express&lt;/code&gt;. In it will be a secrets file called &lt;code&gt;.env&lt;/code&gt;, and in that will be a line &lt;code&gt;SECRET=message&lt;/code&gt;. Variables in that file are available as environment variables, so you can access them from the server's code, e.g. &lt;code&gt;process.env.SECRET&lt;/code&gt; in Node.js.&lt;/p&gt;

&lt;p&gt;The material design team wanted to send a larger payload, with all the customized component styles. It's not a great idea to put a large amount of data in a URL as browsers will handle it differently, and many will cut it off after a certain size. The solution was to instead temporarily store the customized styles in the server of the app, and then let the remix fetch them when it first loads.&lt;/p&gt;

&lt;p&gt;So when the user hits "Remix to Save Theme", it sends the custom styles to the app's server, and is given a unique ID number. We pass the unique ID to the remix, and when the remix first starts up it messages our app "hey, do you have any data for me?" and we can send back the larger data. Once the remix has the data, we can delete it.&lt;/p&gt;

&lt;p&gt;The whole flow looks something like this (in glorious ascii):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5497z4nbwzrumou9k1w2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5497z4nbwzrumou9k1w2.png" alt="An ASCII-art diagram depicting the data transfer flow described above"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you'd like to experiment with the flow yourself, you can try out this simplified demo:&lt;/p&gt;


&lt;div class="glitch-embed-wrap"&gt;
  &lt;iframe src="https://glitch.com/embed/#!/embed/data-provider-example?previewSize=100&amp;amp;path=index.html" alt="data-provider-example on glitch"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Please check out the &lt;a href="http://glitch.com/@material?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;Material Design Team on Glitch&lt;/a&gt; and leave a comment if you build anything using their fantastic resources!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://glitch.com/pricing?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=handbook&amp;amp;utm_content=dev"&gt;Give your Glitch apps superpowers - keep them awake, lift rate limits, and get more memory and disk space.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Getting started with Node + Express on Glitch</title>
      <dc:creator>Potch</dc:creator>
      <pubDate>Wed, 01 Apr 2020 15:10:03 +0000</pubDate>
      <link>https://dev.to/glitch/getting-started-with-node-express-on-glitch-1b0m</link>
      <guid>https://dev.to/glitch/getting-started-with-node-express-on-glitch-1b0m</guid>
      <description>&lt;p&gt;&lt;a href="http://glitch.com?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;Glitch&lt;/a&gt; has a cornucopia of projects you can remix, customize, and make your own. But sometimes you just need a quick mostly-blank slate. That's why we provide three "hello world" apps that are designed to be but mere vessels for your great idea or simple experiment. We want to make sure these projects are up-to-date and reflect the latest best practices, so we periodically give them a fresh coat of paint. Recently I wrote about the &lt;a href="https://dev.to/glitch/hello-to-the-new-hello-sqlite-5044"&gt;changes made to our simple database starter &lt;code&gt;hello-sqlite&lt;/code&gt;&lt;/a&gt;. Next up was &lt;code&gt;hello-express&lt;/code&gt;, which provides a simple &lt;a href="https://nodejs.org/"&gt;Node.js&lt;/a&gt; and &lt;a href="https://expressjs.com/"&gt;express&lt;/a&gt; app!&lt;/p&gt;

&lt;p&gt;We want the &lt;code&gt;hello-&lt;/code&gt; apps to strike a balance between simple and instructive- there should be minimal functionality that's easy to build on top of or replace, but enough there that creators newer to the technologies can get a baseline understanding of how they work. As with &lt;code&gt;hello-sqlite&lt;/code&gt;, it was again decided to add a little more functionality to &lt;code&gt;hello-express&lt;/code&gt; to make it a more "complete" app.&lt;/p&gt;

&lt;p&gt;Previously, the app did little more than use Node and Express to serve a static site that was functionally the same as &lt;a href="https://glitch.com/~hello-webpage?utm_medium=weblink&amp;amp;utm_source=dev.to&amp;amp;utm_campaign=blog&amp;amp;utm_content=dev"&gt;&lt;code&gt;hello-webpage&lt;/code&gt;&lt;/a&gt; (a basic webpage starter). That didn't really show why one would use a server for the task at all! The sample client-side JS now loads information from the server, demonstrating both how to send JSON from the server as well as the basics of using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"&gt;&lt;code&gt;fetch&lt;/code&gt;&lt;/a&gt; on the client side to get the data.&lt;/p&gt;

&lt;p&gt;The big structural change aside, we also did some other tidying and upkeep:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📦 updated Node to latest Long Term Support release, version 12, as well as updated all dependencies&lt;/li&gt;
&lt;li&gt;⚖️ file naming consistency between &lt;code&gt;hello-express&lt;/code&gt; and &lt;code&gt;hello-sqlite&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;✨ shiny modern ES6+ features on both frontend and backend&lt;/li&gt;
&lt;li&gt;📝 rewriting the README to explain the new project structure&lt;/li&gt;
&lt;li&gt;💆‍♀️ some gentle style massage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So with that, enjoy the new &lt;code&gt;hello-express&lt;/code&gt;:&lt;/p&gt;


&lt;div class="glitch-embed-wrap"&gt;
  &lt;iframe src="https://glitch.com/embed/#!/embed/hello-express?path=index.html" alt="hello-express on glitch"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;Merry remixing!&lt;/p&gt;

</description>
      <category>glitch</category>
      <category>express</category>
      <category>node</category>
    </item>
    <item>
      <title>Hello to the new hello-sqlite!</title>
      <dc:creator>Potch</dc:creator>
      <pubDate>Mon, 27 Jan 2020 19:13:02 +0000</pubDate>
      <link>https://dev.to/glitch/hello-to-the-new-hello-sqlite-5044</link>
      <guid>https://dev.to/glitch/hello-to-the-new-hello-sqlite-5044</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjkhQ0FU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/project-avatar/640b1583-cbc9-4718-b20c-31041351c62c.png%3F2019-10-31T19:11:32.508Z" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjkhQ0FU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.glitch.com/project-avatar/640b1583-cbc9-4718-b20c-31041351c62c.png%3F2019-10-31T19:11:32.508Z"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://glitch.com"&gt;Glitch&lt;/a&gt; is full of all sorts awesome projects people can remix  to make their own, but if you’re looking for a quick start or a blank slate, we offer three minimal “hello” projects, where each builds one layer of complexity on the next:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://glitch.com/-hello-webpage"&gt;&lt;code&gt;hello-webpage&lt;/code&gt;&lt;/a&gt; is a simple static webpage with a CSS and JavaScript file&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://glitch.com/~hello-express"&gt;&lt;code&gt;hello-express&lt;/code&gt;&lt;/a&gt; extends &lt;code&gt;hello-webpage&lt;/code&gt; with a &lt;a href="https://nodejs.org"&gt;Node.js&lt;/a&gt; server, using &lt;a href="https://expressjs.com/"&gt;express&lt;/a&gt; to handle requests and serve pages/data&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://glitch.com/~hello-sqlite"&gt;&lt;code&gt;hello-sqlite&lt;/code&gt;&lt;/a&gt; adds a &lt;a href="https://www.npmjs.com/package/sqlite3"&gt;database&lt;/a&gt; to &lt;code&gt;hello-express&lt;/code&gt; to store information between page sessions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;hello-sqlite&lt;/code&gt; is the third-most popular of the starters, and lots of people have used it to explore a new idea. However, the project had a bit of a quirk to it…&lt;/p&gt;

&lt;p&gt;It didn’t really use the database!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why??
&lt;/h2&gt;

&lt;p&gt;When a user views a project on Glitch, they all view the same running instance of that project. When you visit &lt;a href="https://hello-sqlite.glitch.me"&gt;hello-sqlite.glitch.me&lt;/a&gt;, you’re talking to the same database that I see when I go there. If the app was to take user input and store it in the database, I'd see the data you put there and vice-versa. For something like a blog's comment section that’s exactly what we want but for a code demo it didn't really make sense. We also didn’t want to risk someone coming along and putting something not-so-friendly in there for all other users to see!&lt;/p&gt;

&lt;p&gt;Of course people don't use &lt;code&gt;hello-sqlite&lt;/code&gt; directly—they remix it and make it into something else. We found ourselves with a puzzle: how do you make a project behave differently after it's been remixed?&lt;/p&gt;

&lt;p&gt;When you remix a project on Glitch, you get a copy of the project's files at the point at which you remixed it, with a few exceptions. We don't copy anything in a special folder called &lt;code&gt;.data&lt;/code&gt;, which is meant to hold data specific to that single project. For &lt;code&gt;hello-sqlite&lt;/code&gt;, this is where we keep the SQLite database file. We also give special handling to a file called &lt;code&gt;.env&lt;/code&gt;.  This file is intended to hold secrets you need for your project to work, i.e. API keys, or project-specific variables. The file is a series of variable definitions like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# here are my secrets!&lt;/span&gt;
&lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;b33fcabbage
&lt;span class="nv"&gt;MY_GREATEST_FEAR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;notenoughpudding
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When a project is remixed, we remove all the values, but leave the variable names so the person remixing can fill them with their own:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# here are my secrets!&lt;/span&gt;
&lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="nv"&gt;MY_GREATEST_FEAR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Thinking about this, the lightbulb went off! We added a variable to hello-sqlite's &lt;code&gt;.env&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DISALLOW_WRITE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We then added code to the project that let users add items to the database, but with a check to see if that variable was set:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// DISALLOW_WRITE is an ENV variable that gets reset for new projects so you can write to the database&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;DISALLOW_WRITE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// write to the database!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This means the sample database writing code is ready to be customized without having to even un-comment it- once you click remix you're set! If a user is also building a demo, they can set &lt;code&gt;DISALLOW_WRITE&lt;/code&gt; to true as well to get the same benefit.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Is it a bit of a "hack"? Maybe! I think the solution provides the right balance of being somewhat-clever without relying on giving an app special treatment just because it's made by staff.&lt;/p&gt;

&lt;p&gt;Additionally, while adding the new logic we also updated the JS to use widely-supported ES6 syntax and tidy up the documentation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Try it out!
&lt;/h2&gt;


&lt;div class="glitch-embed-wrap"&gt;
  &lt;iframe src="https://glitch.com/embed/#!/embed/hello-sqlite?previewSize=0&amp;amp;attributionHidden=true&amp;amp;sidebarCollapsed=true&amp;amp;path=server.js" alt="hello-sqlite on glitch"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Thanks to everyone who did code review and helped brainstorm on how to make it all work, as well as all the users who have battle-tested the new starter. If you're looking to build a simple app that stores data to the server, try remixing &lt;a href="https://glitch.com/~hello-sqlite"&gt;&lt;code&gt;hello-sqlite&lt;/code&gt;&lt;/a&gt; and let us know what you think.&lt;/p&gt;

&lt;p&gt;Happy Apping!&lt;/p&gt;

</description>
      <category>glitch</category>
      <category>sqlite</category>
      <category>node</category>
      <category>apps</category>
    </item>
  </channel>
</rss>
