<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Jesus Ordosgoitty's blog]]></title><description><![CDATA[Jesus Ordosgoitty's blog]]></description><link>https://blog.jodaz.xyz</link><generator>RSS for Node</generator><lastBuildDate>Fri, 05 Jun 2026 19:35:12 GMT</lastBuildDate><atom:link href="https://blog.jodaz.xyz/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Migrating a Create-React-App monorepo to Vite]]></title><description><![CDATA[I got several years developing React.js applications using creat-react-app as everyone did and never worried too much about tooling until it started to feel like a burden.
My first touch with Vite was with a friend of mine building a Vue frontend, bu...]]></description><link>https://blog.jodaz.xyz/migrating-a-create-react-app-monorepo-to-vite</link><guid isPermaLink="true">https://blog.jodaz.xyz/migrating-a-create-react-app-monorepo-to-vite</guid><category><![CDATA[vite]]></category><category><![CDATA[React]]></category><category><![CDATA[monorepo]]></category><category><![CDATA[create-react-app]]></category><category><![CDATA[Yarn]]></category><dc:creator><![CDATA[Jesús O.]]></dc:creator><pubDate>Thu, 17 Aug 2023 18:08:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/nXt5HtLmlgE/upload/b1f311fd9cb2852d795b3dcb869fea01.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I got several years developing React.js applications using <code>creat-react-app</code> as everyone did and never worried too much about tooling until it started to feel like a burden.</p>
<p>My first touch with Vite was with a friend of mine building a Vue frontend, but it wasn't until a few months ago I was presented with a coworker repo with React.js and it caught up with me the fast bundling and easy-to-start as with CRA.</p>
<p>So, after testing with a quick migration of a previous smaller project, I thought it was time to take this big monorepo to the next level.</p>
<h3 id="heading-context">Context</h3>
<p>I had a two-years old monorepo built with CRA and managed with yarn workspaces. The repo structure was pretty simple, just a <code>/packages</code> directory, each one with a project (in this case, <code>/admin</code> and <code>/app</code> )and also a <code>/lib</code> directory which contains all shared components and utility files.</p>
<pre><code class="lang-bash">/
-- ./ github
-- / packages
---- / admin
------ / public
-------- index.html
------ / src
------ .env
------ config-overrides.js
------ package.json
---- / app
---- / lib
------ /components
------ /assets
------ /api
-- package.json
-- README.md
-- yarn.lock
</code></pre>
<p>Using <code>customize-cra</code> and <code>react-app-rewired</code> packages allowed me to customize the dev compiling process in my <code>config-overrides.js</code>.</p>
<h3 id="heading-initial-setup">Initial setup</h3>
<p>The first thing I did was to install Vite and related packages using yarn in my root directory:</p>
<pre><code class="lang-plaintext">yarn add -W vite @vitejs/plugin-react
</code></pre>
<p>Second, create a <code>vite.config.js</code> in each project's root directory:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span>;
<span class="hljs-keyword">import</span> react <span class="hljs-keyword">from</span> <span class="hljs-string">'@vitejs/plugin-react'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> defineConfig(<span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">build</span>: {
      <span class="hljs-attr">outDir</span>: <span class="hljs-string">'build'</span>,
    },
    <span class="hljs-attr">plugins</span>: [react()],
  };
});
</code></pre>
<p>This code is implementing Vite's React Plugin to define a building setup. I decided to keep <code>build</code> as my directory for bundled assets as its already defined in my Github actions.</p>
<p>Next, I needed to modify my <code>index.html</code> to match <a target="_blank" href="https://vitejs.dev/guide/#index-html-and-project-root">Vite requirements</a>. I started by moving my <code>index.html</code> from <code>/public</code> of each one of my project's root and added a <code>script</code> tag with my JS entry point as my <code>src</code> attribute.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"apple-touch-icon"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"%PUBLIC_URL%/logo192.png"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"manifest"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"%PUBLIC_URL%/manifest.json"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Admin<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">noscript</span>&gt;</span>You need to enable JavaScript to run this app.<span class="hljs-tag">&lt;/<span class="hljs-name">noscript</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"root"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loader-container"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loader"</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
+       <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"/src/index.jsx"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>I am accustomed to JSX files, and also have a small utility to rename all file name extensions so it wasn't a problem for me to rename all files from .js to .jsx.</p>
<p>Then I replaced every instance of <code>react-app-rewired</code> with Vite custom commands on my npm scripts for every project in the <code>/projects</code> directory. For example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692030093165/cb22ac11-d275-4bad-9c84-9103ab44d096.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-custom-configurations">Custom configurations</h3>
<p>At the first server start, I saw on my console a strange error I have never seen before: <code>Uncaught SyntaxError: ambiguous indirect export: default</code>. This time I forgot I had a bunch of SVG assets inside the <code>lib</code> directory.</p>
<p>Solution was simple: for each vite's config file I added support for SVG files with <code>vite-plugin-svgr</code>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span>;
<span class="hljs-keyword">import</span> react <span class="hljs-keyword">from</span> <span class="hljs-string">'@vitejs/plugin-react'</span>;
+ <span class="hljs-keyword">import</span> svgr <span class="hljs-keyword">from</span> <span class="hljs-string">'vite-plugin-svgr'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> defineConfig(<span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">build</span>: {
        <span class="hljs-attr">outDir</span>: <span class="hljs-string">'build'</span>,
    },
    <span class="hljs-attr">plugins</span>: [
        react(),
+        svgr({ <span class="hljs-attr">svgrOptions</span>: { <span class="hljs-attr">icon</span>: <span class="hljs-literal">true</span> } }),
    ],
  };
});
</code></pre>
<p>Another important step during the migration was to replace all <code>process.env</code> in all sites of the project with <code>import.meta.env</code>, and as I was using environment variables on each project, also I had to replace <code>REACT_APP</code> with <code>VITE</code>. In the following example, my <code>configs.js</code> file inside the shared directory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692292748115/21f927e1-540a-469b-8e66-7c54fee61c7b.png" alt class="image--center mx-auto" /></p>
<p>Also, in order to point static files served by Vite in <code>/public</code> directory, I removed all occurrences of <code>%PUBLIC_URL%</code> in <code>index.html</code> file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692289724418/11e9fb91-1919-4f86-aba3-0e4b1226e0b2.png" alt class="image--center mx-auto" /></p>
<p>Finally, removed all previous packages used before.</p>
<pre><code class="lang-plaintext">yarn remove -W react-scripts customize-cra react-app-rewired
</code></pre>
<h3 id="heading-final-thoughts">Final thoughts</h3>
<p>Migrating from <code>create-react-app</code> to Vite was a pretty straightforward process and there are plenty of guides out there, but with a monorepo I thought things were going to be different. Surprisingly it wasn't and the steps were as simple as in a normal repository. Here is the final structure of the repository. Note that there is no <code>config-overrides.js</code> as it is unnecessary now.</p>
<pre><code class="lang-bash">/
-- ./ github
-- / packages
---- / admin
------ / public
------ / src
------ .env
------ index.html
------ vite.config.js
------ package.json
---- / app
---- / lib
------ /components
------ /assets
------ /api
-- package.json
-- README.md
-- yarn.lock
</code></pre>
<hr />
<p>If you found this post useful and would like to stay updated on my work, feel free to connect with me on any of my <a target="_blank" href="https://jodaz.dev/">social profiles</a>.</p>
<p>Share and comment your thoughts on it for more content like this. Thanks!</p>
]]></content:encoded></item><item><title><![CDATA[Building a Timestamp Microservice]]></title><description><![CDATA[Around two months ago I was determined to learn backend development, and so I deep my toe in it with some help of Programming for the Web with JavaScript course. It’s a very good course, though at that time I quickly began to get uninterested in vide...]]></description><link>https://blog.jodaz.xyz/building-a-timestamp-microservice-71a1645f09d9</link><guid isPermaLink="true">https://blog.jodaz.xyz/building-a-timestamp-microservice-71a1645f09d9</guid><dc:creator><![CDATA[Jesús O.]]></dc:creator><pubDate>Tue, 07 Aug 2018 16:14:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1613569216289/58O3erNr3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Around two months ago I was determined to learn backend development, and so I deep my toe in it with some help of <a target="_blank" href="https://www.edx.org/course/programming-web-javascript-pennx-sd4x">Programming for the Web with JavaScript</a> course. It’s a very good course, though at that time I quickly began to get uninterested in videos and quizzes. Now, my college is beginning to ask for real programming projects involving backend and database solutions, and I felt that leaving that course was not the best idea. Anyway, I thought this fCC project may be a good first hands-on experience with backend development. And it was.</p>
<p>It basically consist of an api which will request a date under the form of unix timestamp or a normal English date; you send it one and returns a calculated form of the other back to you. As you’ll need to set up a server, create a module that accepts an api request (as <code>/api/timestamp/</code>) and returns an appropriate JSON object including the date in both formats: This project is one of the best to learn how a web server AND an API works “under the hood”.</p>
<h3 id="first-things-first-app-architecture">First thing’s first — App architecture</h3>
<p>I tried to follow some nice tutorials I found of this topic (all of them are in the notes section) and as I wanted to keep the structure a bit “professional” I create the following:</p>
<pre><code>.
├── <span class="hljs-selector-tag">routes</span>                  
│   └── <span class="hljs-selector-tag">routes</span><span class="hljs-selector-class">.js</span>           
├── <span class="hljs-selector-tag">services</span>                 
│   └── <span class="hljs-selector-tag">timestamp</span><span class="hljs-selector-class">.js</span>
├── <span class="hljs-selector-tag">public</span>
│   ├── <span class="hljs-selector-tag">favicon</span>              
│   ├── <span class="hljs-selector-tag">styles</span>          
│       └── <span class="hljs-selector-tag">main</span><span class="hljs-selector-class">.css</span>
├── <span class="hljs-selector-tag">views</span>                    
│   └── <span class="hljs-selector-tag">index</span><span class="hljs-selector-class">.html</span>
├── <span class="hljs-selector-tag">package</span><span class="hljs-selector-class">.json</span>           
├── <span class="hljs-selector-tag">README</span><span class="hljs-selector-class">.md</span>         
└── <span class="hljs-selector-tag">app</span><span class="hljs-selector-class">.js</span>
</code></pre><h3 id="the-views-or-the-front-page">The views — or the front page</h3>
<p>No templates, jsx, libraries, etc. Just a simple ol’ html file.</p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Timestamp microservice<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"Content-Type"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"text/html;charset=UTF-8"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width;initial-scale=1.0"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"image/png"</span> <span class="hljs-attr">size</span>=<span class="hljs-string">"32x32"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"favicon/favicon-32x32.png"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"[https://fonts.googleapis.com/css?family=Open+Sans](https://fonts.googleapis.com/css?family=Open+Sans)"</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles/main.css"</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Timestamp microservice<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Example usage<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/api/timestamp/2018-08-02"</span>&gt;</span>jesuodz-timestamp.glitch.me/api/timestamp/2018-08-02<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/api/timestamp/1533227498"</span>&gt;</span>jesuodz-timestamp.glitch.me/api/timestamp/1533227498<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/api/timestamp/"</span>&gt;</span>jesuodz-timestamp.glitch.me/api/timestamp/<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Output<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"output-example"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">code</span>&gt;</span>
                    {"unix":1533168000,"utc":"Thu, 02 Aug 2018 00:00:00 GMT"}
                    <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
                    {"unix":1533227498,"utc":"Thu, 02 Aug 2018 16:31:38 GMT"}
                    <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
                    {"unix":1533240424,"utc":"Thu, 02 Aug 2018 20:07:04 GMT"}
                <span class="hljs-tag">&lt;/<span class="hljs-name">code</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><h3 id="the-service">The service</h3>
<p>This is the section of our app that will do our calculations. I’m using <a target="_blank" href="https://momentjs.com">moment.js</a> and the module pattern to build a neat module.</p>
<pre><code>const moment = require(<span class="hljs-string">'moment'</span>);
const <span class="hljs-type">timestamp</span> = { <span class="hljs-keyword">parser</span> : <span class="hljs-keyword">null</span> };

let processed = {
    "unix": "error",
    "utc": "Invalid value"
};

const formatUTC = <span class="hljs-keyword">function</span>(momentObj) {
    <span class="hljs-keyword">return</span> momentObj.format(<span class="hljs-string">'ddd, DD MMM YYYY HH:mm:ss'</span>) + <span class="hljs-string">' GMT'</span>;
}

<span class="hljs-type">timestamp</span>.parser = (request, response) =&gt; {
    const <span class="hljs-keyword">value</span> = request.params.query;

// Handle an empty <span class="hljs-type">date</span> string
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">Object</span>.keys(request.params).length == <span class="hljs-number">0</span>) {    
        let now = moment().utc();
        processed.unix = now.unix();
        processed.utc = formatUTC(now);
        response.send(processed);
        <span class="hljs-keyword">return</span>;
    }

<span class="hljs-keyword">if</span> (isNaN(+<span class="hljs-keyword">value</span>) &amp;&amp; moment(<span class="hljs-keyword">value</span>, <span class="hljs-string">'YYYY-MM-DD'</span>, <span class="hljs-keyword">true</span>).isValid()) {
        processed.unix = moment.utc(<span class="hljs-keyword">value</span>).unix();
        processed.utc = formatUTC(moment(<span class="hljs-keyword">value</span>));
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (!isNaN(+<span class="hljs-keyword">value</span>)) {
        processed.unix = +<span class="hljs-keyword">value</span>;
        processed.utc = formatUTC(moment.utc(moment.unix(+<span class="hljs-keyword">value</span>)));
    } <span class="hljs-keyword">else</span> {
        response.json({"error" : "Invalid value"});
        <span class="hljs-keyword">return</span>;
    }

response.send(processed);
}

module.exports = <span class="hljs-type">timestamp</span>;
</code></pre><p>Remember that conversions from and to unix timestamp are always made in local timezone but fCC user stories said that them should be made in UTC timezone. Moment makes that easier to deal with.</p>
<h3 id="the-routes">The routes</h3>
<pre><code><span class="hljs-keyword">const</span> router = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>).Router();
<span class="hljs-keyword">const</span> timestamp = <span class="hljs-built_in">require</span>(<span class="hljs-string">'../service/timestamp.js'</span>);

<span class="hljs-comment">// Handle routes</span>
router.route(<span class="hljs-string">'/api/timestamp/'</span>).get(timestamp.parser);
router.route(<span class="hljs-string">'/api/timestamp/:query'</span>).get(timestamp.parser);

<span class="hljs-comment">// Main page</span>
router.get(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">request, response</span>) =&gt;</span> {
    response.sendFile(<span class="hljs-string">'index.html'</span>, { root: <span class="hljs-string">'./views/'</span> });
});

<span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = router;
</code></pre><p>At this moment, routing is the most difficult concept to understand for me. It looks counterproductive to me I can’t redirect all-non api requests to the front page, and the only fix I found was to add another handler for those request in the server file.</p>
<h3 id="the-server">The server</h3>
<p>Okay, every express tutorial must explain what <code>app.listen();</code> do but, you know this <em>is not </em>a tutorial and there are plenty of them out there, so I’m keeping things simple and I’ll what are the peeks of this block of code: first I’m importing the <code>routes</code> (all the routing stuff deserve their own file), then I use <code>express.static('public')</code> to serve all static content like css and favicons.</p>
<p>After that, we handle all routes with <code>app.use</code> so our server knows where to send “/api” request and “/” goes to the home page. Also I said before all requests are processed here as 404 errors, here is defined as <code>app.use('*', function);</code> .</p>
<pre><code><span class="hljs-keyword">const</span> express = <span class="hljs-keyword">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = express();
<span class="hljs-keyword">const</span> routes = <span class="hljs-keyword">require</span>(<span class="hljs-string">'./routes/index.js'</span>);

<span class="hljs-comment">// Serve public files</span>
app.<span class="hljs-keyword">use</span>(express.<span class="hljs-built_in">static</span>(<span class="hljs-string">'public'</span>));

<span class="hljs-comment">// Handle routes</span>
app.<span class="hljs-keyword">use</span>(<span class="hljs-string">'/api/'</span>, routes);
app.<span class="hljs-keyword">use</span>(<span class="hljs-string">'/'</span>, routes);
app.<span class="hljs-keyword">use</span>(<span class="hljs-string">'*'</span>, (request, response) =&gt; {
    response.send(<span class="hljs-string">"404 — File not found"</span>);
});

<span class="hljs-comment">// Create and start the server</span>
<span class="hljs-keyword">const</span> port = process.env.PORT || <span class="hljs-string">'3000'</span>; 
app.listen(port, () =&gt; {
    console.log(`Listening on localhost:${port}`);
});
</code></pre><p>Lastly, we fired up the server setting it with any or the default port (<code>process.env.PORT || '3000');</code> ).</p>
<h3 id="some-notes-aside">Some notes aside</h3>
<p>This project was a very good introduction to building a node/express app. Although I still don’t know clearly how routing works, I think it’s still a success (maybe?).</p>
<ul>
<li><p><a target="_blank" href="https://jesuodz-timestamp-1.glitch.me/">Live demo</a> / <a target="_blank" href="https://github.com/jesuodz/timestamp">Source code</a></p>
</li>
<li><p><a target="_blank" href="https://medium.com/codebase/structure-of-a-nodejs-api-project-cdecb46ef3f8">Structure of a Node.js API Project</a>: I totally copy the structure of this article 😅.</p>
</li>
<li><p><a target="_blank" href="https://medium.com/@jrschwane/writing-modular-javascript-pt-1-b42a3bd23685">Writing Modular Javascript</a>: It’s also a good tutorial, though I think it’s better for frontend projects though.</p>
</li>
</ul>
<h3 id="before-you-leave">Before you leave</h3>
<p>If you would love to read even more content like this, feel free to visit me on <a target="_blank" href="https://twitter.com/jodaz_">Twitter</a> a place I usually share my life and thoughts, or just have a look at my <a target="_blank" href="https://jodaz.xyz/">website</a>.</p>
<p>I'd love to count you as my ever-growing group of awesome friends! :)</p>
<p>See you the next time!</p>
]]></content:encoded></item><item><title><![CDATA[I lost my #100DaysOfCode streak… and my computer]]></title><description><![CDATA[A week ago, the motherboard of my computer stopped working. And to make it worse, the capacitors of the screen were failing since December, and in the same day they died. So at that moment I only had my keyboard and a borrowed mouse.
That left me wit...]]></description><link>https://blog.jodaz.xyz/i-lost-my-100daysofcode-streak-and-my-computer-e965eaa6d336</link><guid isPermaLink="true">https://blog.jodaz.xyz/i-lost-my-100daysofcode-streak-and-my-computer-e965eaa6d336</guid><dc:creator><![CDATA[Jesús O.]]></dc:creator><pubDate>Thu, 22 Feb 2018 00:20:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1613569224170/cEkhA_E4h.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A week ago, the motherboard of my computer stopped working. And to make it worse, the capacitors of the screen were failing since December, and in the same day they died. So at that moment I only had my keyboard and a borrowed mouse.</p>
<p>That left me with a bitter feeling. You never know when machines will fail, I always told myself. So I did many backups and alternative plans but suddenly, I found a point in my systems that could fail (the computer) and I don’t have the resources to buy another.</p>
<p>And it broke. Every plan or system I build did not matter after I lost it. That’s what I was thinking around a week ago, after making a <a target="_blank" href="https://github.com/jesuodz/speedstudy">really good progress coding and in college</a>.</p>
<p>So, after three or four hours complaining and fretting, I thought of all those self-improvement and self-help articles and books I read and how much they suck. Unconsciously, I calm down a bit and then I made lists of “things to do” of the house. I followed the list and cleaned my room and part of the house, put everything I should have thrown in the trash and organized almost everything.</p>
<p>Many written documents of that genre can be summarized in simple steps as:</p>
<ul>
<li><p>Calm down</p>
</li>
<li><p>Realize of your current situation</p>
</li>
<li><p>Plan</p>
</li>
<li><p><a target="_blank" href="https://medium.com/@atticusharris/the-difference-between-knowing-the-path-and-walking-the-path-69e0452710ea">And act</a>.</p>
</li>
</ul>
<p>Look for mentors, resources, knowledge, or start learning, programming, reading, writing, marketizing, they are all part of those two last steps. You’re the only one who can make them happen.</p>
<p>On Monday I received another computer. A borrowed one, again. But it doesn’t matter because one day I will have my own, won with my effort. I just need to follow the plan.</p>
<h3 id="before-you-leave">Before you leave</h3>
<p>If you would love to read even more content like this, feel free to visit me on <a target="_blank" href="https://twitter.com/jodaz_">Twitter</a> a place I usually share my life and thoughts, or just have a look at my <a target="_blank" href="https://jodaz.xyz/">website</a>.</p>
<p>I'd love to count you as my ever-growing group of awesome friends! :)</p>
<p>See you the next time!</p>
]]></content:encoded></item><item><title><![CDATA[My 2018 Coding Journey | #100DaysOfCode]]></title><description><![CDATA[Ending last year, I decided to take part in a round 100 Days Of Code Challenge. To know more about the challenge read this blog post by Quincy Larson or this article by Alexander Kallaway, which also explains in detail the foundations of the associat...]]></description><link>https://blog.jodaz.xyz/my-2018-coding-journey-100daysofcode</link><guid isPermaLink="true">https://blog.jodaz.xyz/my-2018-coding-journey-100daysofcode</guid><category><![CDATA[100DaysOfCode]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[personal]]></category><dc:creator><![CDATA[Jesús O.]]></dc:creator><pubDate>Thu, 18 Jan 2018 23:39:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1613567727593/nbFIenIob.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ending last year, I decided to take part in a round 100 Days Of Code Challenge. To know more about the challenge <a target="_blank" href="https://medium.freecodecamp.org/the-crazy-history-of-the-100daysofcode-challenge-and-why-you-should-try-it-for-2018-6c89a76e298d">read this blog post by Quincy Larson</a> or <a target="_blank" href="https://medium.freecodecamp.org/learning-to-code-when-it-gets-dark-e485edfb58fd">this article by Alexander Kallaway</a>, which also explains in detail the foundations of the associated movement.</p>
<p>My plan is to fill the gaps of knowledge in software development and computer science, while building projects along the way. Also, as part of my public commitment I’ll be sharing my progress in github and will also be posting on Medium, at least once a week.</p>
<h1 id="my-background">My background</h1>
<p>I start<span id="rmm"><span id="rmm">e</span></span>d learning HTML, CSS and Javascript in 2014 with tutorials in Codeacademy. At that time, programming seemed so simple with the lessons but horrifly complicated when creating projects. So, I unconsciously decided to stop learning and just do nothing.</p>
<p>Later on 2015, I’ve got interested again and learned python with an <a target="_blank" href="https://www.coursera.org/specializations/python">entire specialization in Coursera</a>. The simplicity of the language caugth my attention and, even though the professor was really good explaining each lesson, my lack of effort made me lose the way and I stopped my learning again. But this time was different because it wasn’t just learning, it was practicing and sharpening the skills I got on previous courses. I didn’t have enough confidence in myself and in the path I had chosen so I simply left it without explanation.</p>
<p>Moving forward in mid 2016 I went back to learning web developmente with Free Code Camp and at the same time I entered in college in the faculty of Computer Science from Universidad de Oriente. That time I felt I wasn’t so bad in software development: it looked like my plan was going on well because much of the topics covered in class I already knew so it was easy to pass the year. Very wrong. Even with a slow pace in May of past year I throw aside all my projects and I didn’t pass one subject as well.</p>
<p>Last months of 2017 were critical for me and my <a target="_blank" href="https://www.nytimes.com/2017/12/02/world/americas/venezuela-nicholas-maduro-inflation-hyperinflation.html">whole country</a>. College was open but working at half paced. I had time to think about what are my problems, what I really care and what I should focus on.</p>
<h1 id="entering-100daysofcode-again">Entering #100DaysOfCode. Again</h1>
<p>I’ve taken this challenge before, and my longest streak was something like 22 days before giving up. Like three times, and once was already this year. But this time I’m not going away and no matter what are the problems I will be facing.</p>
<p>My goal is to grasp as much about web development and computer science in general, and do other stuff along the way as improve my english and college grades. My complete plan is on <a target="_blank" href="https://github.com/jesuodz/speedstudy">github</a> and if everything goes well, I’ll expect to get at least a freelance job.</p>
<h2 id="this-is-the-part-of-the-story-that-becomes-a-little-personal">This is the part of the story that becomes a little personal</h2>
<p>I am somewhat terrified for the amount of work I decided to do and problems I didn’t choose to get. Things are going very bad here in Venezuela and it’s not going to improve in the short term, and combined with my mental problems this becomes a perfect time bomb I don’t want to exploit. I’ve noticed that programming is my only source of stability in this chaos. Maybe it’s impossible to complete my study plan but it’s something I want to do, I need to do and have to because as hard as it might sound, no one will ever do it for me. And in a way, it is fine.</p>
<p>As there’re factors and situations that determine the kind of opportunities one receive from life, there are also moments when one must make decisions and do the right things to change ones future reality. I don’t even know if someone will ever read this. I only want to look back at this post and said “<em>Oh my… English was so bad and I was so dramatic!</em>”. Of course, this isn’t only a blog post, it’s a public commitment for my current self, a reminder to recall what I really want to become and a motivation to keep coding until this post turn in a congratulations letter from my past.</p>
<p>So, here I go!</p>
<h3 id="before-you-leave">Before you leave</h3>
<p>If you would love to read even more content like this, feel free to visit me on <a target="_blank" href="https://twitter.com/jodaz_">Twitter</a> a place I usually share my life and thoughts, or just have a look at my <a target="_blank" href="https://jodaz.xyz/">website</a>.</p>
<p>I'd love to count you as my ever-growing group of awesome friends! :)</p>
<p>See you the next time!</p>
]]></content:encoded></item></channel></rss>