<?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: Kieran</title>
    <description>The latest articles on Forem by Kieran (@rmx).</description>
    <link>https://forem.com/rmx</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%2F480769%2Fdf6e281f-c2ad-4148-b807-f3bed3ba3b02.png</url>
      <title>Forem: Kieran</title>
      <link>https://forem.com/rmx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rmx"/>
    <language>en</language>
    <item>
      <title>URL Shortener Template</title>
      <dc:creator>Kieran</dc:creator>
      <pubDate>Wed, 10 Mar 2021 00:58:16 +0000</pubDate>
      <link>https://forem.com/rmx/url-shortener-template-2om4</link>
      <guid>https://forem.com/rmx/url-shortener-template-2om4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;This article is very old, the project still works but it is no longer maintained.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&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%2Fuploads%2Farticles%2Fskr1jsojh7mhilgck7y8.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%2Fuploads%2Farticles%2Fskr1jsojh7mhilgck7y8.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A very simple URL shortener built with express and lowdb. &lt;a href="https://url-shortener-template.glitch.me" rel="noopener noreferrer"&gt;View the Demo!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Simple and elegant UI.&lt;/li&gt;
&lt;li&gt;Very easy to setup: &lt;a href="https://glitch.com/edit/#!/remix/url-shortener-template" rel="noopener noreferrer"&gt;Remix on Glitch&lt;/a&gt; or &lt;a href="https://repl.it/glitch/url-shortener-template" rel="noopener noreferrer"&gt;Run on Repl.it&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Works well on mobile.&lt;/li&gt;
&lt;li&gt;Open Source on &lt;a href="https://github.com/remiixinc/url-shortener" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and &lt;a href="https://glitch.com/#!/url-shortener-template" rel="noopener noreferrer"&gt;Glitch&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>express</category>
      <category>template</category>
      <category>node</category>
    </item>
    <item>
      <title>Getting website meta tags with node.js!</title>
      <dc:creator>Kieran</dc:creator>
      <pubDate>Thu, 21 Jan 2021 04:09:32 +0000</pubDate>
      <link>https://forem.com/rmx/getting-website-meta-tags-with-node-js-1li5</link>
      <guid>https://forem.com/rmx/getting-website-meta-tags-with-node-js-1li5</guid>
      <description>&lt;p&gt;Recently I was in need of a way to get meta tags for a service I was creating. So I decided to search GitHub for a solution. Unfortunately, everything either didn't work or was very slow. So here we are. &lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First off, install &lt;code&gt;node-fetch&lt;/code&gt; and &lt;code&gt;cheerio&lt;/code&gt; with npm.&lt;/strong&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Next, we need to fetch the HTML of the website we are getting the meta tags from.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; fetch("https://discord.com")
    .then(result =&amp;gt; result.text())
    .then(html =&amp;gt; {
        console.log(html);
    }).catch(error =&amp;gt; {
        console.log(error);
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Now we need to pass this HTML into Cheerio, which will allow us to find meta tags from their attributes.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; fetch("https://discord.com")
    .then(result =&amp;gt; result.text())
    .then(html =&amp;gt; {
        console.log(html);
&lt;span class="gi"&gt;+       const $ = cheerio.load(html);
&lt;/span&gt;    }).catch(error =&amp;gt; {
        console.log(error);
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The way we do this is using code like this...&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;↓&lt;/strong&gt;  find meta elements with property "og:title"&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$('meta[property="og:title"]').attr('content')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;get the chosen elements content attribute  &lt;strong&gt;↑&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;After doing this for all the meta tags I had this...&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; fetch("https://discord.com")
    .then(result =&amp;gt; result.text())
    .then(html =&amp;gt; {
        console.log(html);
        const $ = cheerio.load(html);
&lt;span class="gi"&gt;+       const title = $('meta[property="og:title"]').attr('content') || $('title').text() || $('meta[name="title"]').attr('content')
+       const description = $('meta[property="og:description"]').attr('content') || $('meta[name="description"]').attr('content')
+       const url = $('meta[property="og:url"]').attr('content')
+       const site_name = $('meta[property="og:site_name"]').attr('content')
+       const image = $('meta[property="og:image"]').attr('content') || $('meta[property="og:image:url"]').attr('content')
+       const icon = $('link[rel="icon"]').attr('href') || $('link[rel="shortcut icon"]').attr('href')
+       const keywords = $('meta[property="og:keywords"]').attr('content') || $('meta[name="keywords"]').attr('content')
+       // do something with the variables
&lt;/span&gt;    }).catch(error =&amp;gt; {
        console.log(error);
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You can see the finished product &lt;a href="https://metagrabber.vercel.app/"&gt;here&lt;/a&gt; and view the source on  &lt;a href="https://github.com/RemiixInc/meta-grabber"&gt;GitHub&lt;/a&gt;. A node module is also available &lt;a href="https://www.npmjs.com/package/meta-grabber"&gt;here&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;Sorry if this article sucked, it was my first time writing on this blog.&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>cheerio</category>
    </item>
  </channel>
</rss>
