<?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: Eric O'Brien</title>
    <description>The latest articles on DEV Community by Eric O'Brien (@cireneirbo).</description>
    <link>https://dev.to/cireneirbo</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%2F458903%2Fff0d2733-6a5c-496f-a2cb-7aec551b5d64.jpg</url>
      <title>DEV Community: Eric O'Brien</title>
      <link>https://dev.to/cireneirbo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cireneirbo"/>
    <language>en</language>
    <item>
      <title>Using NodeJS library `dotenv` to Handle Environmental Variables and Secret Keys — Tutorial</title>
      <dc:creator>Eric O'Brien</dc:creator>
      <pubDate>Sat, 11 Jun 2022 00:03:46 +0000</pubDate>
      <link>https://dev.to/cireneirbo/using-nodejs-library-dotenv-to-handle-environmental-variables-and-secret-keys-tutorial-173j</link>
      <guid>https://dev.to/cireneirbo/using-nodejs-library-dotenv-to-handle-environmental-variables-and-secret-keys-tutorial-173j</guid>
      <description>&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;Today, I'm going to show you how use the JavaScript library called &lt;code&gt;dotenv&lt;/code&gt;, which is used to access environment variables in a NodeJS project.\&lt;br&gt;
Environment variables can hold secret keys such as API keys, login credentials, or any other number of information you need to use, but want to keep hidden from the users/internet.&lt;/p&gt;

&lt;p&gt;We will: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv/blob/main/README.md#getting-started"&gt;Start&lt;/a&gt; an empty NodeJS project.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#create-project-files"&gt;Create&lt;/a&gt; all necessary files for project.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#install-dotenv-library-dependencies"&gt;Import&lt;/a&gt; the &lt;code&gt;dotenv&lt;/code&gt; library.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#config-dotenv"&gt;Configure&lt;/a&gt; &lt;code&gt;dotenv&lt;/code&gt; environmental variables.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#create-hello-world-command"&gt;Code&lt;/a&gt; a command using &lt;code&gt;dotenv&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#add-opener-and-create-opener-command"&gt;Code&lt;/a&gt; a more advanced command with &lt;code&gt;opener&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/cireneirbo/demo-dotenv#preparing-to-push-to-github"&gt;Wrap up&lt;/a&gt; the project with some git essentials.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Follow along with this text tutorial, or watch the &lt;a href="https://www.youtube.com/watch?v=0hAahRdB5eA"&gt;video&lt;/a&gt; going over all of this. Or check out the &lt;a href="https://github.com/cireneirbo/demo-dotenv"&gt;GitHub repository&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;So let's start!&lt;/p&gt;
&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;Create a folder for your project however you normally do. I am going to use the terminal, Bash:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to wherever you'd like to save the demo and type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir demo-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Just to make sure we have Node installed, type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;If it doesn't tell you a version number, then you need to install node. Head over to &lt;a href="https://nodejs.org/en/"&gt;https://nodejs.org/en/&lt;/a&gt; and install the version for your OS and then come back.&lt;/li&gt;
&lt;li&gt;Let's also check if you have Git installed too, type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Same as before, if it doesn't tell you a version number, then you need to install git. Head over to &lt;a href="https://git-scm.com/downloads"&gt;https://git-scm.com/downloads&lt;/a&gt; and install the version for your OS and then come back.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we have a folder to work out of, and our set up out of the way. Let's open our IDE next. I use &lt;a href="https://vscodium.com/"&gt;VSCodium&lt;/a&gt;, but you can use whatever you want.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside your IDE, open our project folder that we made already.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we have a fresh slate to work with.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create Project Files
&lt;/h3&gt;

&lt;p&gt;Let's create some empty files in our new folder.\&lt;br&gt;
Make them all in the top-level of the directory - meaning place them all in this folder without any other folders added for depth/nesting.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;main.js&lt;/code&gt; file to run our code in.&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;.env&lt;/code&gt; file to keep our variables in.&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;.gitignore&lt;/code&gt; to follow best practices and avoid pushing unwanted files to GitHub.&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;.env-sample&lt;/code&gt; file to use as an example for the future.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Install &lt;code&gt;dotenv&lt;/code&gt; Library Dependencies
&lt;/h3&gt;

&lt;p&gt;Before we start installing libraries, let's get our &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the terminal, type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's go to &lt;a href="https://www.npmjs.com/package/dotenv"&gt;npm's dotenv page&lt;/a&gt; to find the package and get downloading and usage instructions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the terminal, type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This installs the library so we can use it in our project.&lt;/p&gt;
&lt;h3&gt;
  
  
  Config Dotenv
&lt;/h3&gt;

&lt;p&gt;Now we need to import it properly.\&lt;br&gt;
If you check the &lt;a href="https://www.npmjs.com/package/dotenv"&gt;npm site&lt;/a&gt;, it says we need to add this near the top of &lt;code&gt;main.js&lt;/code&gt; (always keep at the bottom of any other imports you might add to your own projects):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('dotenv').config();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a bit different than most packages, and should always be kept at the bottom of your imports, and above any code you're calling an environment variable with.\&lt;br&gt;
Great! Now we have our project ready to code!&lt;/p&gt;
&lt;h3&gt;
  
  
  Create "Hello World" Command
&lt;/h3&gt;

&lt;p&gt;Let's start coding!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Below the &lt;code&gt;dotenv&lt;/code&gt; import, type:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Hello, " + process.env.name + "!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will give us a "Hello World"-type message when we run it correctly. But, first we need to assign our name to the environment variable &lt;code&gt;name&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the &lt;code&gt;.env&lt;/code&gt; file and add:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name="User"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Save your project and we are ready to run it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the terminal, type:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It works! Cool!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello User!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add &lt;code&gt;opener&lt;/code&gt; and Create "Opener" Command
&lt;/h3&gt;

&lt;p&gt;Now let's add something a bit more useful to give you a better idea of how to use environment variables.&lt;/p&gt;

&lt;p&gt;Go to the &lt;a href="https://www.npmjs.com/package/opener"&gt;npm opener&lt;/a&gt; website. &lt;code&gt;opener&lt;/code&gt; is a library that allows us to automatically open a website in a new browser tab/window.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;opener&lt;/code&gt; in your project directory's terminal with:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i opener
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Let's import it to &lt;code&gt;main.js&lt;/code&gt; now. At the top of the &lt;code&gt;main.js&lt;/code&gt; (above the &lt;code&gt;dotenv&lt;/code&gt; config) type:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const opener = require('opener');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then, at the bottom of your &lt;code&gt;main.js&lt;/code&gt; file type:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;opener(process.env.url);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will call whatever URL we have at the &lt;code&gt;.env&lt;/code&gt; variable &lt;code&gt;url&lt;/code&gt;. But that variable doesn't exist yet, so let's go fix that!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On a new line in &lt;code&gt;.env&lt;/code&gt;, type:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;url="https://nodejs.org/en/"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open the NodeJS website when we run our program. Let's test it out now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the terminal run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty cool, huh?&lt;/p&gt;

&lt;h3&gt;
  
  
  Preparing to Push to GitHub
&lt;/h3&gt;

&lt;p&gt;One last thing to know is that &lt;code&gt;.env&lt;/code&gt; (or &lt;code&gt;node_modules/&lt;/code&gt; because they take up too much unnecessary space) files should never be uploaded to Github or any other version control system. If you do, anyone can read your private environment variables!&lt;/p&gt;

&lt;p&gt;To get around this, we need a &lt;code&gt;.gitignore&lt;/code&gt; file. This is usually created for you as an option if you make a new project with GitHub, but we will do it from scratch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Previously, we created a &lt;code&gt;.gitignore&lt;/code&gt; file. Open it, and inside add:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will now exclude your &lt;code&gt;.env&lt;/code&gt; file and &lt;code&gt;node_modules/&lt;/code&gt; from ever being uploaded with git to a version control. &lt;br&gt;
We will want to create a sample &lt;code&gt;.env&lt;/code&gt; to show our potential users (or just remind ourselves in the future) what to do with their &lt;code&gt;.env&lt;/code&gt; file if they are going to use our program themselves.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In our &lt;code&gt;.env-sample&lt;/code&gt; file, add:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name="your-name"
url="your-url"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;.env-sample&lt;/code&gt; will upload to version control because it isn't listed in our &lt;code&gt;.gitignore&lt;/code&gt; file. It is merely there as a reference, and it has no sensitive information. This is crucial when using a private API key or secrets.&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://github.com/cireneirbo/demo-dotenv"&gt;GitHub repository&lt;/a&gt;!&lt;br&gt;
Well there you have it folks. &lt;code&gt;dotenv&lt;/code&gt; in all of it's glory! Good luck and have fun! :)&lt;/p&gt;

&lt;p&gt;Feel free to follow me and check out my &lt;a href="https://linktr.ee/codeethicallywitheric"&gt;Linktr.ee&lt;/a&gt; for more!&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Red Rectangle Press - A YouTube voice to text email command line program</title>
      <dc:creator>Eric O'Brien</dc:creator>
      <pubDate>Mon, 11 Apr 2022 22:59:06 +0000</pubDate>
      <link>https://dev.to/cireneirbo/the-red-rectangle-press-a-youtube-voice-to-text-email-command-line-program-296h</link>
      <guid>https://dev.to/cireneirbo/the-red-rectangle-press-a-youtube-voice-to-text-email-command-line-program-296h</guid>
      <description>&lt;h1&gt;
  
  
  the-red-rectangle-press
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Overview of My Submission
&lt;/h3&gt;

&lt;p&gt;The Red Rectangle Press is an application that converts the audio from a YouTube video to text and then sends it via email. &lt;/p&gt;

&lt;h4&gt;
  
  
  What It Does
&lt;/h4&gt;

&lt;p&gt;RRP is a utility tool to increase the accessibility of content on YouTube. You might be wondering - "Why might someone prefer an emailed transcript over the original video?" Well, there are many reasons, some of which include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited hearing ability.&lt;/li&gt;
&lt;li&gt;Captions are not available for that video.&lt;/li&gt;
&lt;li&gt;Wifi access will be limited at a time when the user could watch the video.&lt;/li&gt;
&lt;li&gt;To be able to search for keywords and only digest the parts they are interested in.&lt;/li&gt;
&lt;li&gt;To use the content in an article or research project. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  How It Does It
&lt;/h4&gt;

&lt;p&gt;RRP uses several packages to handle the functionality of the program. The command line input is acquired through using &lt;a href="https://www.npmjs.com/package/readline-sync"&gt;readline-sync&lt;/a&gt; which asks users for a YouTube link and an email address. &lt;a href="https://www.npmjs.com/package/youtube-mp3-downloader"&gt;YouTube mp3 Downloader&lt;/a&gt; is used to specify YouTube videos from which the audio data should be extracted, converted to MP3, and temporarily stored on disk.&lt;br&gt;
&lt;a href="https://github.com/deepgram/deepgram-node-sdk"&gt;DeepGram SDK&lt;/a&gt; then converts the stored MP3 file to a text transcript. And then &lt;a href="https://www.npmjs.com/package/@sendgrid/mail"&gt;SendGrid Mail&lt;/a&gt; is utilized to send the transcript as an email to a specified address.&lt;/p&gt;

&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;Accessibility Advocates: Use Deepgram to improve user accessibility. Think about user input, accessing media or live events, and improving understanding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Code on GitHub
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/cireneirbo/the-red-rectangle-press"&gt;https://github.com/cireneirbo/the-red-rectangle-press&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;Command line screenshot:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cDnPUoT3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3223wtp4geihf6x9ygcg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cDnPUoT3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3223wtp4geihf6x9ygcg.PNG" alt="Command line Screenshot" width="880" height="557"&gt;&lt;/a&gt;&lt;br&gt;
Proof of email receipt and layout:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r2KDzawi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4uh189y3uucqol6ciwm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r2KDzawi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4uh189y3uucqol6ciwm.PNG" alt="Email transcript received" width="880" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hackwithdg</category>
    </item>
  </channel>
</rss>
