<?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: Christopher Howard</title>
    <description>The latest articles on DEV Community by Christopher Howard (@webplayground).</description>
    <link>https://dev.to/webplayground</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%2F1095957%2F128a0c03-ceee-426c-a2c5-7dc505b9e7f9.png</url>
      <title>DEV Community: Christopher Howard</title>
      <link>https://dev.to/webplayground</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/webplayground"/>
    <language>en</language>
    <item>
      <title>// WPimagines, A Free AI image generator(yup, another one)</title>
      <dc:creator>Christopher Howard</dc:creator>
      <pubDate>Wed, 06 Sep 2023 19:11:14 +0000</pubDate>
      <link>https://dev.to/webplayground/-wpimagines-a-free-ai-image-generatoryup-another-one-3gaa</link>
      <guid>https://dev.to/webplayground/-wpimagines-a-free-ai-image-generatoryup-another-one-3gaa</guid>
      <description>&lt;p&gt;I just launched my ai image generator last week. It is a text to image generator that can view &amp;amp; download images. I'm currently working on a paid version that will let you edit downloaded images, gives you tutorials on prompting &amp;amp; let's you export images to various sizes.&lt;/p&gt;

&lt;p&gt;You can check it out &lt;a href="https://www.wpimagines.com"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>promptengineering</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>How to use res.download() to download images</title>
      <dc:creator>Christopher Howard</dc:creator>
      <pubDate>Wed, 02 Aug 2023 18:55:28 +0000</pubDate>
      <link>https://dev.to/webplayground/how-to-use-resdownload-to-download-images-3gk8</link>
      <guid>https://dev.to/webplayground/how-to-use-resdownload-to-download-images-3gk8</guid>
      <description>&lt;h2&gt;
  
  
  What does res.download() do?
&lt;/h2&gt;

&lt;p&gt;An express.js method that downloads the file at the path specified as an attachment. It takes these arguments.&lt;/p&gt;

&lt;p&gt;Path — string, the path to the file you want to download.&lt;/p&gt;

&lt;p&gt;Filename — string, the file name you want to call the file, if absent will use the filename in the path.&lt;/p&gt;

&lt;p&gt;Options — object, an object used to specify options.&lt;/p&gt;

&lt;p&gt;Callback — function, a function to do when it completes successfully or throws an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using res.download() normally
&lt;/h2&gt;

&lt;p&gt;Here I'm going to make a html document with 2 buttons in it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PJ8zUPoQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl4kv9p3c4ro98ii2ufl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PJ8zUPoQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl4kv9p3c4ro98ii2ufl.png" alt="The html for the article res.download()." width="700" height="307"&gt;&lt;/a&gt;&lt;br&gt;
When I click the first button I'll reroute the browser with window.location.href to the "/download" route on the express server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NXcY-aE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xcjkomw3wy9y06p9sbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NXcY-aE3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xcjkomw3wy9y06p9sbm.png" alt="The javascript for res.download()" width="700" height="171"&gt;&lt;/a&gt;&lt;br&gt;
On the server, I'll make a get request to the "/download" route. In the response, I'll use the res.download() method with the path, filename &amp;amp; callback functions specified. When it comes back successful, I'll console.log() a message. The file will be downloaded when I hit this route. Also, the browser will remain on the same view or page even since res.end() was called instead of res.render() or res.redirect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7pLvBQOX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me7uq1v9teivvgo1ilct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7pLvBQOX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me7uq1v9teivvgo1ilct.png" alt="The res.download() method on the server" width="700" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Res.download() automatically calls res.end()
&lt;/h2&gt;

&lt;p&gt;When res.download() completes successfully it automatically calls res.end() after the callback function. That means you don't need to call res.end(), res.json() or any other method that ends the response. Doing so will throw an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Res.download() errors
&lt;/h2&gt;

&lt;p&gt;When calling a method that ends res.download(), you will receive a headers already sent error. This means that res.end() was called twice. To check for this, you could see if res.headersSent property is true. This property checks to see if a response was already sent.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jy5q4UYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1x1twwizbbftoldkbvn2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jy5q4UYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1x1twwizbbftoldkbvn2.png" alt="Checking the error on res.download() method" width="700" height="247"&gt;&lt;/a&gt;&lt;br&gt;
The other error that will be thrown is if the path to file is wrong or the file being downloaded does not exist. If this happens you'll want to send a response status saying the file is not found.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N9dBqNeP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvh4msl9hsbppyl4zk12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N9dBqNeP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvh4msl9hsbppyl4zk12.png" alt="The file not found error on res.download()" width="700" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using res.download() with fetch request
&lt;/h2&gt;

&lt;p&gt;If you need to use fetch to send some form info or do something else, you will have to make a middleman route an order to use res.download(). Res.download() will fire, but it will not download the file. I made a call to "/downloadImage" route, then returned a message. When the fetch request completes, I then reroute the browser to the "/download" route to get the file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G2AYjFGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49mnuyyix1st1fremovl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G2AYjFGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49mnuyyix1st1fremovl.png" alt="The fetch to download an image." width="700" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Extras
&lt;/h2&gt;

&lt;p&gt;The express docs for res.download() says that browsers will prompt the user for download. I have not run into this myself. Here is &lt;a href="https://codesandbox.io/p/sandbox/article-how-to-use-res-download-to-download-images-rx2sw9"&gt;code&lt;/a&gt; putting res.download() into action.&lt;br&gt;
To find more articles from me visit &lt;a href="https://www.webplyground777.com"&gt;webplayground.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>express</category>
      <category>node</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>How a Content Editable Element Works</title>
      <dc:creator>Christopher Howard</dc:creator>
      <pubDate>Thu, 06 Jul 2023 15:36:02 +0000</pubDate>
      <link>https://dev.to/webplayground/how-a-content-editable-element-works-2c76</link>
      <guid>https://dev.to/webplayground/how-a-content-editable-element-works-2c76</guid>
      <description>&lt;h2&gt;
  
  
  Focus on Content Editable Element
&lt;/h2&gt;

&lt;p&gt;You can use a ce(content editable) element as a text editor or a content management system. These articles are going to be using a ce as a text editor. Ce elements can be focused on like a input or text area element. Once you focus on a ce, you can start typing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Elements Within a Ce Text Editor
&lt;/h2&gt;

&lt;p&gt;When you make a ce text editor, you want to start with an element such as a paragraph or a div with some text content in it. You can press the enter key &amp;amp; the text editor will start a new line with a new element in it. If you press enter while there is text after the cursor, you will move the text after the cursor to the new element. The element you start the te with will be created every time you press enter.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; tag
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; tag inside the text editor is important. When you focus in on the te, the cursor needs an element or a text node to start at. So, when I press enter it creates a new &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with a &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; tag inside of it. The &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; tag is what the cursor is selecting so I can type in it. Once I start typing the &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; tag disappears because it’s just a line break, there is no elements or content inside of it. If I delete all the text the &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; will reappear, if I hit delete again the element will be deleted.&lt;/p&gt;

&lt;p&gt;My name is Chris. You can find more articles about html/css &amp;amp; javascript on the &lt;a href="//www.webplayground777.com"&gt;webplayground&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>html</category>
      <category>contenteditable</category>
      <category>webdesign</category>
    </item>
  </channel>
</rss>
