<?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: Rafael Lima</title>
    <description>The latest articles on DEV Community by Rafael Lima (@rafaellimags).</description>
    <link>https://dev.to/rafaellimags</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%2F414100%2F3b3e0597-6b93-4f86-b28a-c6ec28e218da.jpeg</url>
      <title>DEV Community: Rafael Lima</title>
      <link>https://dev.to/rafaellimags</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafaellimags"/>
    <language>en</language>
    <item>
      <title>Get values from selected keys</title>
      <dc:creator>Rafael Lima</dc:creator>
      <pubDate>Tue, 06 Oct 2020 18:27:25 +0000</pubDate>
      <link>https://dev.to/rafaellimags/get-values-from-selected-keys-e2d</link>
      <guid>https://dev.to/rafaellimags/get-values-from-selected-keys-e2d</guid>
      <description>&lt;p&gt;Got text values corresponding to the selected keys, sent from the backend server through an object, by a GET request to the HTML form, using a Nunjucks tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server.get('/route/:id', (req, res) =&amp;gt; {
    return res.render('page', { data })
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;{% if object.key == "value"  %} text value  {% endif %}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;p&gt;🏗 Project: &lt;a href="https://github.com/rafaellimags/gym-manager"&gt;https://github.com/rafaellimags/gym-manager&lt;/a&gt;&lt;/p&gt;

</description>
      <category>log</category>
    </item>
    <item>
      <title>Creating users ID</title>
      <dc:creator>Rafael Lima</dc:creator>
      <pubDate>Tue, 06 Oct 2020 01:54:53 +0000</pubDate>
      <link>https://dev.to/rafaellimags/creating-users-id-4ec7</link>
      <guid>https://dev.to/rafaellimags/creating-users-id-4ec7</guid>
      <description>&lt;p&gt;Fix duplicated user IDs when adding a new one right before delete the last user.&lt;/p&gt;

&lt;p&gt;❌Wasn't working like this&lt;br&gt;
&lt;/p&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;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It happens that when you delete a user before the last, and create a new user, the new user gets the same id as the last. Making two users to have the same ID.&lt;/p&gt;

&lt;p&gt;✔So i made it like this:&lt;br&gt;
&lt;/p&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;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&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;lastUser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lastUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Of course that is far from the best way to create unique user IDs, since we have node uniqid and other node packages. But it was made to be simple, just to get used with the language as i get better in logic and solve problems without an out of the box solution.&lt;/p&gt;

</description>
      <category>log</category>
    </item>
    <item>
      <title>Fix path reference</title>
      <dc:creator>Rafael Lima</dc:creator>
      <pubDate>Sat, 03 Oct 2020 20:48:10 +0000</pubDate>
      <link>https://dev.to/rafaellimags/fix-path-reference-1698</link>
      <guid>https://dev.to/rafaellimags/fix-path-reference-1698</guid>
      <description>&lt;p&gt;It took me some minutes to realize the cause of the problem. The console showed &lt;code&gt;Uncaught SyntaxError: Unexpected identifier&lt;/code&gt; at &lt;code&gt;scripts.js:1&lt;/code&gt;. But the thing is nothing was wrong in scripts file. Even the line, 1 where the console was pointing the error to.&lt;/p&gt;

&lt;p&gt;Going further inside the scripts file in browser's console, the only message was the error message from a &lt;code&gt;if&lt;/code&gt; statement in case the data was not found. But that message was in another file.&lt;br&gt;
After more or less 30 minutes, i found a dumb syntax error from where the &lt;code&gt;scripts.js&lt;/code&gt;was being called.&lt;/p&gt;

&lt;p&gt;As i was using the express middleware to watch for static files in the public folder, i suppose the express was reaching to the the folder and expecting a path then, if there was one, of course.&lt;/p&gt;

&lt;p&gt;🔧 How it was set up&lt;br&gt;
&lt;code&gt;server.use(express.static("public"))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;💬 How file was called&lt;br&gt;
&lt;code&gt;&amp;lt;script src="./scripts.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;❌ The error&lt;br&gt;
&lt;code&gt;Uncaught SyntaxError: Unexpected identifier&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At this point, the framework was trying to access the path this way: folder/public./scripts.js&lt;/p&gt;

&lt;p&gt;✅ The solution&lt;br&gt;
&lt;code&gt;&amp;lt;script src="/scripts.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;💡 How should it be avoided?&lt;br&gt;
Understanding more about file paths and how to use them in Linux&lt;/p&gt;

&lt;p&gt;Simply remove the dot from the path that was avoiding express to get to the script file.&lt;/p&gt;

&lt;p&gt;💭 Conclusion&lt;br&gt;
When you are new, almost everything seems very complex and it is hard to deconstruct your thoughts to know where and how every piece of code connect with each other, wich prevents you from having a more analytical thinking.&lt;/p&gt;




&lt;p&gt;🏗 The project: &lt;a href="https://github.com/rafaellimags/gym-manager"&gt;https://github.com/rafaellimags/gym-manager&lt;/a&gt;&lt;/p&gt;

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