<?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" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Grozav - Awesome Front-end, UI, UX, and DX Blog]]></title><description><![CDATA[Awesome articles, tutorials, and videos about front-end web development, user interface, user experience and developer experience design]]></description><link>https://grozav.com/</link><image><url>https://grozav.com/favicon.png</url><title>Grozav - Awesome Front-end, UI, UX, and DX Blog</title><link>https://grozav.com/</link></image><generator>Ghost 4.0</generator><lastBuildDate>Sun, 12 Apr 2026 10:28:31 GMT</lastBuildDate><atom:link href="https://grozav.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Making v-model Model Value Optional  in Vue.js]]></title><description><![CDATA[While writing my Vue.js UI Library, Inkline, I had to find a way to make components work both with and without providing a model value (v-model). Here's what I found.]]></description><link>https://grozav.com/making-v-model-optional-in-vuejs/</link><guid isPermaLink="false">6052eadf40bd792ee506a4be</guid><category><![CDATA[Vue.js]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Thu, 18 Mar 2021 11:35:15 GMT</pubDate><media:content url="https://grozav.com/content/images/2021/03/optionally-controlled-components-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2021/03/optionally-controlled-components-1.jpg" alt="Making v-model Model Value Optional  in Vue.js"><p>While writing my Vue.js UI Library, <a href="https://inkline.io">Inkline</a>, I had to find a way to make some components work both with and without providing a model value (<code>v-model</code>). While it&apos;s not a common scenario, it&apos;s something that you&apos;ll definitely come across if you&apos;re writing a library and you&apos;re serious about <strong>Developer Experience (DX)</strong>.</p>
<p>I call them <strong>Optionally Controlled Components</strong>, because they&apos;re supposed to work out of the box without providing a <code>v-model</code>, but will give you complete control over their state if you do provide a <code>v-model</code>.</p>
<h2 id="themenuexample">The Menu Example</h2>
<p>One prime example of an Optionally Controlled Component would be a menu that can be opened (expanded) or closed (collapsed). Let&apos;s call the component simply <code>MyMenu</code>.</p>
<p>From a Developer Experience perspective, you&apos;ll probably want your library user to be able to drop a <code>&lt;my-menu&gt;</code> into their code and start adding collapsible content right away, without having to worry about handling its open or closed state.</p>
<p>Here&apos;s what the component would look like without <code>v-model</code> support:</p>
<pre><code class="language-html">&lt;template&gt;
    &lt;div class=&quot;my-menu&quot;&gt;
        &lt;button @click=&quot;toggleMenu&quot;&gt;
            Menu
        &lt;/button&gt;
        &lt;menu v-show=&quot;open&quot;&gt;
            &lt;slot /&gt;
        &lt;/menu&gt;
    &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
export default {
    name: &apos;MyMenu&apos;,
    data() {
        return {
            open: false
        };
    },
    methods: {
        toggleMenu() {
            this.open = !this.open;
        }
    }
}
&lt;/script&gt;
</code></pre>
<h2 id="theoptionalmodelvalue">The Optional Model Value</h2>
<p>So far so good. Let&apos;s consider the following scenario: your user wants to be able to open or close the menu from somewhere else. We know we can open and close the menu internally at this point, but how do we allow the library user to optionally control the state?</p>
<p>There&apos;s a future-proof solution I found, that will save you a lot of trouble. Here&apos;s what it looks like:</p>
<pre><code class="language-html">&lt;template&gt;
    &lt;div class=&quot;my-menu&quot;&gt;
        &lt;button @click=&quot;toggleMenu&quot;&gt;
            Menu
        &lt;/button&gt;
        &lt;menu v-show=&quot;open&quot;&gt;
            &lt;slot /&gt;
        &lt;/menu&gt;
    &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
export default {
    name: &apos;MyMenu&apos;,
    emits: [
        &apos;update:modelValue&apos;
    ],
    props: {
        modelValue: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            open: this.modelValue
        };
    },
    methods: {
        toggleMenu() {
            this.open = !this.open;
            this.$emit(&apos;update:modelValue&apos;, this.open);
        }
    },
    watch: {
        modelValue(value) {
            this.open = value;
        }
    }
}
&lt;/script&gt;
</code></pre>
<p>Try a basic example out live on <a href="https://codesandbox.io/s/optionally-controlled-components-43y0b?file=/src/components/MyMenu.vue">CodeSandbox</a>.</p>
<p>You can see above that I&apos;ve added the usual <code>modelValue</code> prop to provide <code>v-model</code> support in Vue 3, but mainly I&apos;ve done three things:</p>
<ul>
<li>I&apos;m setting the initial value of our internal <code>open</code> state property to be equal to the one provided via <code>v-model</code>. This works wonders, because when there&apos;s no <code>v-model</code> it would be equal to the specified default, <code>false</code> in our case.</li>
<li>I&apos;m emitting an <code>update:modelValue</code> event every time I change the value of <code>this.open</code> internally</li>
<li>I&apos;ve added a watcher that ensures I&apos;m always keeping the internal <code>open</code> value in sync with the incoming external <code>modelValue</code> prop.</li>
</ul>
<figure class="kg-card kg-image-card" style="text-align: center;">
    <img src="https://grozav.com/content/images/2021/03/optionally-controlled-components-complex-1.gif" alt="Making v-model Model Value Optional  in Vue.js">
</figure>
<h2 id="conclusion">Conclusion</h2>
<p>Awesome, isn&apos;t it? It&apos;s important to never forget about Developer Experience. Something as small as this can add up to precious hours of saved development time if done correctly and consistently.</p>
<p>I hope you learned something interesting today. I&apos;d love to hear how the Optionally Controlled Components pattern helped you out, so feel free to reach out to me. <strong>Happy coding!</strong></p>
<p><small><strong>P.S.</strong> Have you heard that Inkline 3 is coming with Vue 3 support? Read more about it on <a href="https://github.com/inkline/inkline/issues/207">GitHub</a>.</small></p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Unit Testing Vue Lifecycle Methods]]></title><description><![CDATA[Testing Vue components is incredibly simple. However, lifecycle methods are almost always overlooked.]]></description><link>https://grozav.com/unit-testing-vue-lifecycle-methods/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a62b</guid><category><![CDATA[Vue.js]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Thu, 21 May 2020 14:19:49 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/05/unit-testing-vue-lifecycle-methods.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/05/unit-testing-vue-lifecycle-methods.jpg" alt="Unit Testing Vue Lifecycle Methods"><p>Testing Vue components is incredibly simple. However, lifecycle methods are almost always overlooked. While testing lifecycle methods isn&apos;t difficult, I haven&apos;t found too many resources out there that explain how to do this.</p>
<h2 id="writingthecomponent">Writing the Component</h2>
<p>First, let&apos;s say we have a component called <code>MyLifecycleComponent.vue</code>. This component calls an <code>initialize</code> method during the <code>mounted</code> lifecycle step:</p>
<pre><code class="language-html">&lt;template&gt;
    &lt;div&gt;Hello lifecycle component!&lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
export default {
    name: &apos;MyLifecycleComponent&apos;,
    methods: {
        initialize() {
            console.log(&apos;initialized&apos;);
        }
    },
    mounted() {
        this.initialize();
    }
}
&lt;/script&gt;
</code></pre>
<p>A very basic test would be to check whether the <code>initialize()</code> method gets called during the <code>mounted()</code> lifecycle.</p>
<h2 id="writingthetest">Writing the Test</h2>
<p>By default, lifecycle methods are called automatically while the component is being created, therefore they&apos;re supposed to be called only once.</p>
<p>What I want to do is to make the lifecycle methods callable inside the tests. The component instance <code>wrapper.vm</code> does not expose lifecycle methods by default, therefore we need to add them when mounting the component <code>wrapper</code>.</p>
<pre><code class="language-js">let wrapper;

beforeEach(() =&gt; {
    wrapper = shallowMount(MyLifecycleComponent, {
        methods: {
            mounted: MyLifecycleComponent.mounted
        }
    });
});
</code></pre>
<p>It&apos;s good practice to mount the component before each test in order to have a clean state. As a rule of thumb, it&apos;s best to keep things as simple as possible, that&apos;s why we&apos;re not testing the actual effect of the <code>initialize</code> method, but whether it has been called.</p>
<p>In order to check whether a method has been called, we use <code>jest.spyOn()</code> to create a spy. The spy contains information on whether the method has been called or not, how many times it has been called, and what it has been called with.</p>
<pre><code class="language-js">import MyLifecycleComponent from &apos;@/components/MyLifecycleComponent&apos;;
import { shallowMount } from &apos;@vue/test-utils&apos;;

describe(&apos;MyLifecycleComponent&apos;, () =&gt; {
    let wrapper;

    beforeEach(() =&gt; {
        wrapper = shallowMount(MyLifecycleComponent, {
            methods: {
                mounted: MyLifecycleComponent.mounted
            }
        });
    });

    describe(&apos;mounted()&apos;, () =&gt; {
        it(&apos;should call initialize method&apos;, () =&gt; {
            const spy = jest.spyOn(wrapper.vm, &apos;initialize&apos;);
            
            wrapper.vm.mounted();
            
            expect(spy).toHaveBeenCalled();
        });
    });
});
</code></pre>
<h2 id="conclusion">Conclusion</h2>
<p>Testing lifecycle methods is hassle free when you know how to do it. All of the code presented here can be found in <a href="https://github.com/alexgrozav/blog/tree/master/unit-testing-vue-lifecycle-methods-example">this repository</a>.</p>
<p>When unit testing, I always aim for a 100% test coverage because it keeps me out of trouble when I refactor my code.</p>
<pre><code class="language-js"> PASS  tests/unit/MyLifecycleComponent.spec.js
  MyLifecycleComponent
    mounted()
      &#x2713; should call initialize method (27ms)

  console.log src/components/MyLifecycleComponent.vue:10
    initialized

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.051s
Ran all test suites.
</code></pre>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Vue Emitter Design Pattern: Broadcast and Dispatch]]></title><description><![CDATA[The Vue Emitter Design Pattern is the all-around solution for programatic event-based child-parent communication]]></description><link>https://grozav.com/vue-emitter-design-pattern-broadcast-dispatch/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a62a</guid><category><![CDATA[Vue.js]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Sun, 12 Apr 2020 21:00:00 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/blue-lighthouse-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/blue-lighthouse-1.jpg" alt="Vue Emitter Design Pattern: Broadcast and Dispatch"><p>Working with events in Vue.js works great out of the box, but what happens if you want to send an event to a specific parent or child component?</p>
<p>The Vue Emitter Design Pattern is the all-around solution for programatic event-based child-parent communication. To provide this functionality, we&apos;re going to implement two essential methods: <code>broadcast</code> and <code>dispatch</code>.</p>
<h2 id="broadcast">Broadcast</h2>
<p>Broadcasting means emitting an event from a parent component to all child components that have a specific name. This is useful when you want to update several child components.</p>
<p>To implement broadcasting, we&apos;re going to recursively descend the children of the parent component. In order for it to be easy to reuse, we&apos;ll write a Vue mixin inside a <code>BroadcastMixin.vue</code> file:</p>
<pre><code class="language-js">/**
 * Broadcast an event with given params to specific child properties
 *
 * @param componentName
 * @param eventName
 * @param params
 */
function broadcast (componentName, eventName, params) {
    this.$children.forEach(child =&gt; {
        const name = child.$options.name;
        if (name === componentName) {
            child.$emit.apply(child, [eventName].concat(params));
        } else {
            broadcast.apply(child, [componentName, eventName].concat([params]));
        }
    });
}

export default {
    methods: {
        broadcast (componentName, eventName, params) {
            broadcast.call(this, componentName, eventName, params);
        }
    }
}
</code></pre>
<p>With the code being written as a Vue mixin, using it is as simple as:</p>
<pre><code class="language-js">import BroadcastMixin from &apos;./mixins/BroadcastMixin.vue&apos;;

export default {
    name: &apos;ParentComponent&apos;,
    mixins: [
        BroadcastMixin
    ],
    methods: {
        broadcastSomething() {
            this.broadcast(&apos;ChildComponent&apos;, &apos;input&apos;, 42);
        }
    }
}
</code></pre>
<h2 id="dispatch">Dispatch</h2>
<p>Dispatching means emitting an event from a child component to a parent component that has a specific name. This is useful in scenarios where the parent needs to be notified of something happening in a child component.</p>
<p>To implement dispatching, we&apos;re going to recursively ascend the parents of the child component until we find the one we&apos;re looking for. Again, we&apos;ll be using a Vue mixin in order to have reusable code. Here&apos;s the <code>DispatchMixin.vue</code> file:</p>
<pre><code class="language-js">/**
 * Dispatch an event from child to parents of given type
 *
 * @param componentName
 * @param eventName
 * @param params
 */
function dispatch (componentName, eventName, params) {
    let parent = this.$parent || this.$root;
    let name = parent.$options.name;
    while (parent &amp;&amp; (!name || name !== componentName)) {
        parent = parent.$parent;
        if (parent) {
            name = parent.$options.name;
        }
    }
    if (parent) {
        parent.$emit.apply(parent, [eventName].concat(params));
    }
}

export default {
    methods: {
        dispatch (componentName, eventName, params) {
            dispatch.call(this, componentName, eventName, params);
        }
    }
}
</code></pre>
<p>To use the above Vue mixin, import it and add it to the mixins array:</p>
<pre><code class="language-js">import DispatchMixin from &apos;./mixins/DispatchMixin.vue&apos;;

export default {
    name: &apos;ChildComponent&apos;,
    mixins: [
        DispatchMixin
    ],
    methods: {
        dispatchSomething() {
            this.dispatch(&apos;ParentComponent&apos;, &apos;input&apos;, 42);
        }
    }
}
</code></pre>
<h2 id="conclusions">Conclusions</h2>
<p>I&apos;ve used this design pattern quite a lot in <a href="https://inkline.io">Inkline</a>, my Vue.js UI/UX Framework. Make sure you check it out if you haven&apos;t already.</p>
<p>An use case where I found it to be of tremendous importance was reinitializing an array of values based on child components. To make sure that the array data is always in sync, child components would call a <code>synchronize</code> event whenever they would get mounted or destroyed.</p>
<p>The Vue Emitter Design Pattern will prove itself particularly useful when creating reusable related components that can have any level of nesting. I&apos;d love to hear your thoughts down below.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[The Power of NPM Scripts]]></title><description><![CDATA[Npm scripts are my absolute favorite feature of npm. They're a much easier, more flexible alternative to task runners.]]></description><link>https://grozav.com/power-of-npm-scripts/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a627</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Mon, 18 Jun 2018 10:54:10 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/power-of-npm-scripts-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/power-of-npm-scripts-1.jpg" alt="The Power of NPM Scripts"><p>Npm scripts are my absolute favorite feature of npm. They&apos;re a much easier, more flexible alternative to task runners.</p>
<p><strong>So, what is a npm script?</strong> A npm script is, well, exactly what the name says. It&apos;s a command-line script that is run through npm. It facilitates the use of locally installed dependencies without making them available system-wide.</p>
<p>This <strong>allows you to write common application routines</strong> without the need for too many configuration files. The common way to do this used to be using Gulp or Grunt, or even using bash scripts. Lately, a lot of developers are moving over to npm scripts because of how simple and flexible they are.</p>
<h2 id="howtowritenpmscripts">How to write npm scripts</h2>
<p>When you talk about npm, you talk about <code>package.json</code>, of course. The <code>package.json</code> file has a <code>scripts</code> field where you define all the routines.</p>
<p>If you don&apos;t recall from the <a href="https://grozav.com/node-js-simplified-tutorial-part-4-npm-packages/">previous tutorial</a>, the <code>package.json</code> file is your package&apos;s configuration file, generated after running <code>npm init</code>.</p>
<pre><code class="language-json">// File: package.json

{
    &quot;name&quot;: &quot;my-package&quot;,
    &quot;description&quot;: &quot;This is a sample project for the Node.js Simplified Tutorial.&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;scripts&quot;: {
        ...
    },
    &quot;dependencies&quot;: {
        ...
    },
    &quot;devDependencies&quot;: {
        ...
    }
}
</code></pre>
<p>The part we&apos;re interested in now is the <code>&quot;scripts&quot;</code> field. That&apos;s where we define named command-line scripts that pass through npm.</p>
<h3 id="yourfirstscript">Your first script</h3>
<p>Let&apos;s go ahead and add a very simple script called <code>hello</code>, that writes an output to the command line terminal. To do so, write the name of the script and the command associated to it in quotes.</p>
<p>The script we&apos;re writing is a plain bash script:</p>
<pre><code class="language-json">// File: package.json

{
    ...
    &quot;scripts&quot;: {
        &quot;hello&quot;: &quot;echo &apos;Hello npm scripts!&apos;&quot;
    }
}
</code></pre>
<p>Next, any npm script you write can be executed using the <code>npm run</code> command.</p>
<pre><code class="language-bash">npm run hello
</code></pre>
<h3 id="thestartscript">The <code>start</code> script</h3>
<p>Perhaps the <strong>most popular npm script</strong> ever is the <code>start</code> script:</p>
<pre><code class="language-json">{
    ...
    &quot;scripts&quot;: {
        &quot;start&quot;: &quot;node index.js&quot;
    }
}
</code></pre>
<p>As you&apos;ve seen above, starting a command is done using the <code>npm run</code> command. The <code>start</code> script, however, is a built-in script and we can optionally ommit the <code>run</code> keyword for it.</p>
<pre><code class="language-command-line">npm start
</code></pre>
<h2 id="scriptcomposition">Script composition</h2>
<p>One common use for npm scripts is as an alternative to task runners. Npm scripts make it easy for you to execute long lines using simple commands.</p>
<p>In my experience, one of the best things about using npm scripts is script composition. This means that <strong>npm allows you to compose large npm scripts out of multiple smaller ones</strong>, allowing you to use <code>npm run my-script</code> inside of another script.</p>
<p>Let&apos;s take a look at the <code>dev</code> npm script I wrote here:</p>
<pre><code class="language-json">{
    ...
    &quot;scripts&quot;: {
        &quot;start&quot;: &quot;node index.js&quot;,
        &quot;webpack&quot;: &quot;webpack --config config/webpack.config.js&quot;,
        &quot;dev&quot;: &quot;npm run webpack &amp;&amp; npm start&quot;
    }
}
</code></pre>
<p>If you are not very comfortable with terminal commands, what you need to know is:</p>
<ul>
<li>running npm scripts <strong>in series</strong> is done using a double ampersand <code>&amp;&amp;</code>, the second command executing after the successful execution of the first one.</li>
<li>running npm scripts <strong>in parallel</strong> is done using a single ampersand <code>&amp;</code> (on UNIX-based systems) or the <a href="https://www.npmjs.com/package/concurrently" rel="nofollow">concurrently</a> package, with the two commands executing at the same time.</li>
</ul>
<p><strong>Running <code>npm run dev</code> will run both the <code>start</code> and the <code>webpack</code> scripts</strong> I&apos;ve defined above. Yup, you can do that and it&apos;s awesome!</p>
<h2 id="scriptexecutionhooks">Script execution hooks</h2>
<p>Npm scripts have before and after script events which I call <strong>script execution hooks</strong>. They&apos;re basically other scripts that will be executed before or after the script you&apos;re running. Hooks can be added by simply prepending the <code>pre</code> (before) and <code>post</code> (after) keyword to your npm script name.</p>
<p>Let&apos;s say that, for example, you have a script called <code>count</code>. If you&apos;d like to add a pre-execution hook to it, you would call it <code>precount</code>. If you&apos;d like to add a post-execution hook, you would call it <code>postcount</code>. Simple, isn&apos;t it?</p>
<pre><code class="language-json">{
    ...
    &quot;scripts&quot;: {
        &quot;precount&quot;: &quot;echo &apos;1&apos;&quot;,
        &quot;count&quot;: &quot;echo &apos;2&apos;&quot;,
        &quot;postcount&quot;: &quot;echo &apos;3&apos;&quot;
    }
}
</code></pre>
<p>Now, when running <code>npm run count</code>, npm will actually execute three scripts, in the following order: <code>precount</code>, <code>count</code>, <code>postcount</code>. The displayed output will be <code>1 2 3</code>.</p>
<h2 id="builtinnpmscripts">Built-in npm scripts</h2>
<p>There&apos;s a number of special scripts that npm treats differently, such as the <code>start</code> script you&apos;ve seen above. The built-in scripts are used for basic commands, as well as for some <code>pre</code> (before) and <code>post</code> (after) script execution hooks.</p>
<p><strong>Note</strong>: The built-in scripts can be executed without the <code>run</code> keyword.</p>
<pre><code class="language-bash">npm start
</code></pre>
<p>Keep in mind that <strong>most built-in npm scripts come with a default behaviour</strong>. However, you can override the behaviour or add a custom command to be executed alongside the command&apos;s default behaviour.</p>
<ul>
<li><code>install</code>: Installs the package and all its dependencies.<br>
The built-in npm script hooks for <code>npm install</code> are: <code>preinstall</code>, <code>postinstall</code></li>
<li><code>uninstall</code>: Uninstalls the package.<br>
The built-in npm script hooks for <code>npm uninstall</code> are: <code>preuninstall</code>, <code>postuninstall</code></li>
<li><code>start</code>: Starts the package execution.<br>
The built-in npm script hooks for <code>npm start</code> are: <code>prestart</code>, <code>poststart</code></li>
<li><code>stop</code>: Stops the package execution.<br>
The built-in npm script hooks for <code>npm stop</code> are: <code>prestop</code>, <code>poststop</code></li>
<li><code>restart</code>: Restarts the package execution. Default runs the stop and start scripts.<br>
The built-in npm script hooks for <code>npm restart</code> are: <code>prerestart</code>, <code>postrestart</code></li>
<li><code>prepare</code>: Runs before the package is packed and published, and on local npm install without any arguments.</li>
<li><code>publish</code>: Publishes the package to npm.<br>
The built-in npm script hooks for <code>npm publish</code> are: <code>prepublish</code>, <code>prepublishOnly</code>, <code>postpublish</code></li>
<li><code>version</code>: Runs after bumping the package version.<br>
The built-in npm script hooks for <code>npm version</code> are: <code>preversion</code>, <code>postversion</code></li>
<li><code>shrinkwrap</code>: Locks down dependency versions for publication.<br>
The built-in npm script hooks for <code>npm shrinkwrap</code> are: <code>preshrinkwrap</code>, <code>postshrinkwrap</code></li>
<li><code>pack</code>: Creates a tarball from a package.<br>
The built-in npm script hooks for <code>npm pack</code> are: <code>prepack</code>, <code>postpack</code></li>
<li><code>test</code>: Runs the tests of the package.<br>
The built-in npm script hooks for <code>npm test</code> are: <code>pretest</code>, <code>posttest</code></li>
</ul>
<p>I&apos;m sure that not all of them will be useful to you, but some will be nice to know for when you&apos;re creating your own package.</p>
<h2 id="whatsnext">What&apos;s next?</h2>
<p>Now that you&apos;ve learned about the utility of npm scripts, it&apos;s time to create your first real Node.js application.</p>
<p><strong>As always, I&apos;d love to hear your opinion about this article!</strong> Make sure to leave a comment down below.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[All About NPM Packages]]></title><description><![CDATA[Node's package manager, npm, is a very powerful tool used to share your code as packages. Every npm package starts with a package.json file. ]]></description><link>https://grozav.com/guide-to-npm-packages/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a625</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Wed, 16 May 2018 20:21:44 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/black-box2-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/black-box2-1.jpg" alt="All About NPM Packages"><p>Every Node.js project starts with a <code>package.json</code> file.</p>
<p>In the <a href="https://grozav.com/understanding-nodejs-modules/">previous part</a> of the Node.js Simplified Tutorial series, you learned about exporting and requiring Node.js modules. Here, I&apos;ll talk about npm, an indispensable tool in your Node.js experience.</p>
<p><strong>Node&apos;s package manager</strong>, suggestively named <strong>npm</strong>, is a very powerful tool used to share your code as packages. Not only that, but it allows you to reuse code written by other developers inside your own package, as dependencies. Each package is identified using a <code>package.json</code> file.</p>
<p>The <code>package.json</code> file is used for specifying important details about your project such as its name, description, version, entry file, production dependencies, and development dependencies. You can even define command line scripts to be run through npm, slowly eliminating the need for task runners.</p>
<h2 id="creatinganpmpackage">Creating a npm package</h2>
<p>Creating your first package is as simple as writing a single command line. Open up your terminal, go to your project&apos;s root folder and run the following command:</p>
<pre><code class="language-bash">npm init
</code></pre>
<p>This is going to ask you to provide basic details about your npm package. The <code>name</code> and <code>description</code> you provide here are the ones that will be used when publishing the package to <a href="https://npmjs.org" rel="nofollow">npm</a>. Don&apos;t worry about the <code>entry point</code> for now: the default is <code>index.js</code> and you&apos;ll see why that is in the following section.</p>
<pre><code class="language-yaml">name: (project) my-project
version: (1.0.0) 1.0.0
description: This is a sample project for the Node.js Simplified Tutorial.
entry point: (index.js) index.js
test command: 
git repository: https://github.com/alexgrozav
keywords: nodejs
author: Alex Grozav
license: (ISC) ISC
</code></pre>
<p>After you&apos;re done , <strong>the command will generate a file called <code>package.json</code></strong> that will contain all the details you provided. This will be the configuration of your npm package.</p>
<p>Your <code>package.json</code> file should look like this:</p>
<pre><code class="language-json">{
  &quot;name&quot;: &quot;my-project&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;description&quot;: &quot;This is a sample project for the Node.js Simplified Tutorial&quot;,
  &quot;main&quot;: &quot;index.js&quot;,
  &quot;scripts&quot;: {
    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
  },
  &quot;repository&quot;: {
    &quot;type&quot;: &quot;git&quot;,
    &quot;url&quot;: &quot;https://github.com/alexgrozav&quot;
  },
  &quot;keywords&quot;: [
    &quot;nodejs&quot;
  ],
  &quot;author&quot;: &quot;Alex Grozav&quot;,
  &quot;license&quot;: &quot;ISC&quot;
}
</code></pre>
<p>The <code>package.json</code> file does a lot more than provide basic package details. It&apos;s the place where you specify the development and production dependencies that your package has, but we&apos;ll get back to that later in this article.</p>
<p>For now, it&apos;s easiest to <strong>think of every Node.js project as a package</strong> and to <strong>think of every package as a module</strong>.</p>
<h2 id="requiringanpmpackage">Requiring a npm package</h2>
<p>In my previous tutorial you&apos;ve learned how Node.js handles require statements for relative paths. You can also require npm packages in the same way.</p>
<p>It&apos;s important to understand that <strong>when you require a package you will actually require the file specified in the <code>main</code> field of your <code>package.json</code> file</strong>. This is same as the <code>entry point</code> you specified during the <code>npm init</code> step.</p>
<pre><code class="language-js">const myPackage = require(&apos;package-name&apos;);
</code></pre>
<p>After path resolving, Node.js will require the file specified in the <code>main</code> field of the <code>package-name/package.json</code> file or, if the <code>main</code> field isn&apos;t specified, it will look for an <code>index.js</code> file:</p>
<pre><code class="language-js">const myPackage = require(&apos;package-name/index.js&apos;);
</code></pre>
<h2 id="addingpackagedependencies">Adding package dependencies</h2>
<p>Undoubtedly, the best thing about creating your own npm package is that you can specify, install and then use other developer&apos;s packages. This saves up a lot of time, with the <a href="https://npmjs.org" rel="nofollow">npm registry</a> offering more than 600,000 packages for you to use.</p>
<p>When I was learning Node.js, I didn&apos;t understand the difference between production and development dependencies very clearly. Here&apos;s what is different:</p>
<h3 id="installingdependenciesforproduction">Installing dependencies for production</h3>
<p>Production dependencies are the ones that your package actually depends on. These dependencies will need to be installed alongside your own package in order for it to run. Don&apos;t worry though, npm handles the dependencies for you.</p>
<p>What this basically means is that, when someone else installs your package, the production dependencies you specify will be automatically installed together with it.</p>
<pre><code class="language-bash">npm install --save lodash
</code></pre>
<p><strong>Note</strong>: You can use the <code>-S</code> shorthand instead of <code>--save</code>.</p>
<h3 id="installingdependenciesfordevelopment">Installing dependencies for development</h3>
<p>Specifying development dependencies is perfect for installing packages that help you get to the final version of your package, but do not directly affect the functionality of your package.</p>
<p>Development dependencies usually provide you with capabilities such as testing, compiling, bundling, and other things needed during development only.</p>
<pre><code class="language-bash">npm install --save-dev gulp
</code></pre>
<p><strong>Note</strong>: You can use the <code>-D</code> shorthand instead of <code>--save-dev</code>.</p>
<h3 id="installingpackagesglobally">Installing packages globally</h3>
<p>Global packages are made available system-wide. You should only install packages globally if they offer a command line executable or if their documentation suggests you to do so.</p>
<p>Typically, you will need install test runners, testing frameworks, task runners, languages, and bundlers globally.</p>
<pre><code class="language-bash">npm install --global gulp-cli
</code></pre>
<p><strong>Note</strong>: You can use the <code>-g</code> shorthand instead of <code>--global</code>.</p>
<h3 id="thenode_modulesfolder">The <code>node_modules</code> folder</h3>
<p>Every time you install a local dependency, npm downloads and installs the package and its dependencies inside a folder called <code>node_modules</code>, where you can find and explore all of your package&apos;s dependencies.</p>
<p>After each saved installation, your production or development dependencies will be listed inside the <code>package.json</code> file under <code>dependencies</code> and <code>devDependencies</code>, respectively:</p>
<pre><code class="language-json">{
    ...
    &quot;dependencies&quot;: {
        &quot;lodash&quot;: &quot;^4.17.5&quot;
    },
    &quot;devDependencies&quot;: {
        &quot;gulp&quot;: &quot;^3.9.1&quot;
    }
}
</code></pre>
<p>If you want to <strong>install all the dependencies of an existing package</strong>, simply run the install command without any argument:</p>
<pre><code class="language-bash">npm install
</code></pre>
<h2 id="publishingyourpackagetonpm">Publishing your package to npm</h2>
<p>When you&apos;re ready to share your package with the world (if you want to, of course), you can publish your package to the <a href="https://npmjs.org" rel="nofollow">public npm repository</a>.</p>
<ul>
<li>First, <strong>make sure you&apos;re logged into npm</strong> using the login command. This will ask you for your npm username, password, and email.</li>
</ul>
<pre><code class="language-bash">npm login
</code></pre>
<ul>
<li>Next, make sure you have specified a <strong>unique name</strong>, <strong>valid repository url</strong>, and <a href="https://semver.org/" rel="nofollow"><strong>semantic version</strong></a> in your <code>package.json</code>. Publish your package by running the publish command:</li>
</ul>
<pre><code class="language-bash">npm publish
</code></pre>
<ul>
<li>Now <strong>your package is available for installation</strong> to other developers using the name you&apos;ve specified.</li>
</ul>
<pre><code class="language-bash">npm install --save your-package-name
</code></pre>
<p>Lately, good npm package names have been pretty scarce, like domains, because everyone is trying to reserve a nice name for themselves.</p>
<h2 id="whatsnext">What&apos;s next?</h2>
<p>Now you&apos;re ready to create packages, install dependencies and perhaps, even give something back to the open source world someday.</p>
<p>In my <a href="https://grozav.com/power-of-npm-scripts/">Power of NPM Scripts</a> article, I&apos;ve written about the now-popular npm scripts and how they work. They&apos;re a great addition to your workflow, and you won&apos;t need to rely on a task runner such as <a href="https://gulpjs.com" rel="nofollow">gulp</a> or <a href="https://gruntjs.com" rel="nofollow">grunt</a> anymore.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Understanding Node.js Modules]]></title><description><![CDATA[Understanding how module exports and require works is essential towards understanding Node.js.]]></description><link>https://grozav.com/understanding-nodejs-modules/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a626</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Wed, 09 May 2018 19:02:59 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/red-macarons-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/red-macarons-1.jpg" alt="Understanding Node.js Modules"><p>When I started learning about Node.js modules, I remember being confused about them.</p>
<blockquote>
<p><strong>Modules</strong> are self-contained entities that provide distinct functionality, allowing them to be changed, added, or removed as needed in order to form a complete system.</p>
</blockquote>
<p><strong>Modules are essential for splitting your code into reusable components</strong>. They&apos;re such a simple concept, yet the underlying mechanism is so complex.</p>
<p>First thing you&apos;ll need to know is that all the dependencies in Node.js are handled using two core built-in objects:</p>
<ul>
<li>The <code>require</code> object &#x2015; available across your Node.js application as a function</li>
<li>The <code>module</code> object &#x2015; because each file represents a module, it is local and individual to each file</li>
</ul>
<p>The <code>module</code> object is usually used for <strong>exporting</strong> things from a file, and the <code>require</code> function is used for <strong>importing</strong> the exported things into a file.</p>
<h2 id="moduleexports">Module exports</h2>
<p>You can think of exporting as choosing what values (just about anything) you&apos;re making available from the current file within another file. You define what gets exported using the <code>module.exports</code> object.</p>
<pre><code class="language-js">module.exports = {
  greeting: &apos;Hello Node.js!&apos;
};
</code></pre>
<h3 id="usingmoduleexportsvsexports">Using <code>module.exports</code> vs <code>exports</code></h3>
<p>Something I&apos;ve encountered when looking at other projects is the keyword <code>exports</code> by itself. The two are one and the same object, <code>exports</code> being a simple reference to <code>module.exports</code>.</p>
<p>Node.js makes the <code>exports</code> variable available behind the scenes by doing the following:</p>
<pre><code class="language-js">var exports = module.exports = {};
</code></pre>
<h2 id="moduleimporting">Module importing</h2>
<p>Whenever you require a file, Node.js goes through a series of actions that will ensure your file is loaded properly:</p>
<ul>
<li><strong>Resolving the path</strong> &#x2015; First, Node.js determines the absolute path of the file you&apos;re requiring, relative to the file that you&apos;re importing in.</li>
<li><strong>Loading the file</strong> &#x2015; Next, Node.js determines what type of content the file contains. You can also require <code>.json</code> files and Node.js knows how to differentiate the two based on the provided file extension.</li>
<li><strong>Scoping the code</strong> &#x2015; The <code>require</code> and <code>module</code> objects are local to the file they&apos;re in. Each individual file has it&apos;s own scope.</li>
<li><strong>Evaluating the code</strong> &#x2015; Next, the Virtual Machine evaluates the loaded code inside the newly created scope, limited the file where you&apos;re importing it in.</li>
<li><strong>Caching the file</strong> &#x2015; To achieve better performance, Node.js caches the loaded file. Once you&apos;ve require a file, it will be ready to be reused.</li>
</ul>
<pre><code class="language-js">const importedModule = require(&apos;./path/to/file&apos;);
</code></pre>
<h3 id="resolvingmodulepaths">Resolving module paths</h3>
<p>During the path resolving step, Node.js gives you a lot of flexibility. It&apos;s important that you understand the difference between requiring paths and requiring packages.</p>
<p>You should keep in mind that <strong>you don&apos;t need to specify the <code>.js</code> extension</strong>, because Node.js&apos;s path resolving mechanism adds it automatically.</p>
<p>Another thing I found very useful when writing Node.js applications is that <strong>you can specify a folder path</strong> in your <code>require</code> statement, and then the <code>index.js</code> file inside the specified folder will be targeted.</p>
<pre><code class="language-js">require(&apos;./path/to/file&apos;);
</code></pre>
<p>The <code>require</code> statement above, used with a relative path, will be resolved for you in one of the following ways:</p>
<pre><code class="language-js">// The path refers a .js file
require(&apos;/home/user/path/to/file.js&apos;); 

// The path refers to a folder
require(&apos;/home/user/path/to/file/index.js&apos;);
</code></pre>
<p>If the specified path is nor a relative or an absolute path, it will be treated as a npm package. You&apos;ll learn more about creating and requiring npm packages in the next tutorial.</p>
<pre><code class="language-js">require(&apos;package-name&apos;);
</code></pre>
<h2 id="exportandrequireinaction">Export and require in action</h2>
<p>Understanding how module exports and imports work together is essential towards understanding Node.js. The way Node.js handles modules work is fairly complicated, but the interface for using modules is not complicated at all.</p>
<p>When I started out, I understood what <code>require()</code> does. What I didn&apos;t know, however, was about the existence of the <code>module.exports</code> object and how it interferes with requiring modules. One thing I really take pleasure in doing is learning through practical examples, so let&apos;s write a simple program.</p>
<p>Let&apos;s write a small file called <code>greetings.js</code>, where we&apos;ll export a simple function for saying hello.</p>
<pre><code class="language-js">// File: greetings.js

function sayHello (name) {
  console.log(&apos;Hello &apos; + name);
}

function sayGoodbye (name) {
  console.log(&apos;Goodbye &apos; + name);
}

module.exports = {
  sayHello: sayHello,
  sayGoodbye: sayGoodbye
};
</code></pre>
<p>Next, let&apos;s import and use the greeting inside an <code>index.js</code> file. Make sure to place the two files in the same folder.</p>
<pre><code class="language-js">// File: index.js

const greetingsModule = require(&apos;./greetings&apos;);

greetingsModule.sayHello(&apos;Node.js&apos;);
greetingsModule.sayGoodbye(&apos;Node.js&apos;);
</code></pre>
<p>Last but not least, run the program as you&apos;ve learned in the previous tutorial.</p>
<pre><code class="language-bash">node index.js
</code></pre>
<h2 id="whatsnext">What&apos;s next?</h2>
<p>This is merely an introduction to how module exporting and importing works. There&apos;s a lot more to learn about it, and I&apos;ll try my best to bring you up to speed with the best practices on the topic.</p>
<p>I&apos;ve covered fundamental functionality such as requiring npm packages and creating your own package in <a href="https://grozav.com/guide-to-npm-packages/">All About NPM Packages</a>. Make sure you read it!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Installing Node.js the Right Way]]></title><description><![CDATA[Installing Node.js is very straightforward. In this tutorial you'll learn how to install Node.js using nvm, the Node Version Manager.]]></description><link>https://grozav.com/installing-nodejs-the-right-way/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a624</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Sun, 06 May 2018 19:05:44 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/green-forest-road.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/green-forest-road.jpg" alt="Installing Node.js the Right Way"><p>Installing Node.js is very straightforward. In this tutorial you&apos;ll learn how to install it using nvm, the Node Version Manager.</p>
<p>In the <a href="https://grozav.com/introduction-to-nodejs/">first part</a> of the Node.js Tutorial series, you&apos;ve learned what Node.js is and why you should learn it. Since you&apos;re reading this, I assume you&apos;ve decided that <strong>Node.js is worth learning</strong>. It&apos;ll be quite a beautiful journey, I assure you!</p>
<p>If you want to get started right away, download and install the Node.js binaries by visiting the official <a href="https://nodejs.org/en/download/" rel="nofollow">Node.js Downloads</a> page. However, if you want to do it the <strong>right way</strong>, keep reading to learn about nvm.</p>
<h2 id="installingnvm">Installing nvm</h2>
<p>If you want to add more Node.js versions to use for different applications, or to simply keep your Node.js environment organized, I&apos;d recommend installing <strong>nvm</strong>. Here&apos;s how to install it for your specific operating system:</p>
<p><strong>MacOS and Linux</strong><br>
Follow the steps specified in the <a href="https://github.com/creationix/nvm">nvm</a> GitHub repository, or run the following command in your command line Terminal:</p>
<pre><code class="language-bash">curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
</code></pre>
<p><strong>Windows</strong><br>
The windows version requires you to <a href="https://github.com/coreybutler/nvm-windows/releases/download/1.1.5/nvm-setup.zip" rel="nofollow">Download</a> and Install the executable from the <a href="https://github.com/coreybutler/nvm-windows" rel="nofollow">nvm-windows</a> GitHub repository.</p>
<h4 id="usingnvm">Using nvm</h4>
<p>To list the versions of Node.js available to install, run the following command:</p>
<pre><code class="language-bash">nvm ls-remote
</code></pre>
<p>This is going to give you a long list of available Node.js versions. I usually choose to install one of the LTS (Long Term Support) versions, which are proven to be stable and have all the latest bug fixes.</p>
<p>For this tutorial, we&apos;ll install version <strong>12.14.0 (LTS: Erbium)</strong>.</p>
<pre><code class="language-bash">nvm install 12.14.0
</code></pre>
<p>To check if the chosen node version has been installed properly, run:</p>
<pre><code class="language-bash">node --version
</code></pre>
<p>This will return the version number of the currently active Node.js binary. If everything is working, it should say <code>12.14.0</code>.</p>
<h4 id="switchingbetweenversions">Switching between versions</h4>
<p>If you&apos;ve installed multiple versions using nvm, you can switch between them using the <code>nvm use</code> command:</p>
<pre><code class="language-bash">nvm use 12.14.0
</code></pre>
<h2 id="gettingstartedhelloworld">Getting started &#x2015; Hello world!</h2>
<p>Now that your Node.js is up and ready to be put to use, we can write and run a small test program, to make sure that you&apos;re ready for the next part.</p>
<p>Let&apos;s start by creating a file called <code>index.js</code>. Open up your IDE (<a href="https://atom.io" rel="nofollow">Atom</a>, <a href="https://www.sublimetext.com" rel="nofollow">Sublime</a>, <a href="https://code.visualstudio.com" rel="nofollow">VS Code</a>, or <a href="https://www.jetbrains.com/webstorm/" rel="nofollow">WebStorm</a>), create a new file and save it with the name <code>index.js</code>.</p>
<p>Once you&#x2019;re done with that, write your first line of Node.js:</p>
<pre><code class="language-js">// File: index.js

console.log(&quot;Hello Node.js!&quot;);
</code></pre>
<p>Let&apos;s run the program! <strong>To execute your Node.js file</strong>, go back to your command line terminal and navigate to the directory in which you&apos;ve saved the <code>index.js</code> file. Once you&apos;re there, run:</p>
<pre><code class="language-bash">node index.js
</code></pre>
<p>You can see that it will log <code>Hello Node.js!</code> to the terminal.</p>
<h2 id="whatsnext">What&apos;s next?</h2>
<p><strong>Well, that was simple!</strong> If you&apos;ve read around about Node.js, you&apos;ve surely come across <code>require()</code> statements, used to include code from other files into your application&apos;s entry point (the <code>index.js</code> file).</p>
<p>Next, head over to <a href="https://grozav.com/understanding-nodejs-modules/">Understanding Node.js Modules</a> where you&apos;ll learn about modules, how they work, and why they&apos;re so important.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Introduction to Node.js]]></title><description><![CDATA[Introducing a truly understandable Node.js tutorial series for beginner and intermediate developers.]]></description><link>https://grozav.com/introduction-to-nodejs/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a623</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Thu, 26 Apr 2018 08:03:05 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/04/yellow-brochure.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/04/yellow-brochure.jpg" alt="Introduction to Node.js"><p>Introducing a truly understandable Node.js tutorial series for beginner and intermediate developers.</p>
<p>Whether you&apos;re just starting out or you already have some Node.js experience, this tutorial will guide you through all you need to know to find your way trough any existing Node.js project, as well as writing your own Node.js projects from scratch. Except for having some experience with Javascript, there&apos;s no prior knowledge needed.</p>
<p>I&apos;m writing this tutorial series because when I started out, everything about Node.js seemed so complicated. The code sample on the official website made it seem like it&apos;s some complicated server language, and I didn&apos;t know how it compares to what I previously knew. Having come from PHP and Ruby, it felt like I wouldn&apos;t be able to write the same things using Javascript. Fortunately, nothing could be further from the truth.</p>
<p>In this tutorial you&apos;ll learn what Node.js is, what it isn&apos;t, how it&apos;s going to help your development career and how you can use it to be more productive in your web development projects. Let&apos;s start!</p>
<h2 id="whatisnodejs">What is Node.js?</h2>
<p>Node.js is V8, the JavaScript engine running inside Google Chrome, bundled together with a couple of libraries for I/O (Input/Output) operations. Basically, it&apos;s what Chrome is using to interact with files on your computer using code written in Javascript.</p>
<p>Where does all the confusion come from? Node.js isn&apos;t any special variation of Javascript, it is just plain, modern Javascript, but it&apos;s running everywhere instead of just your browser.</p>
<p>When running Javascript in the browser, you&apos;re enclosed in a sandbox environment that doesn&apos;t allow you to interact with files on your computer, ensuring a secure browsing environment for the site&apos;s visitors, while executing Javascript using Node.js is meant to behave like a standard programming language.</p>
<p>Node.js became so popular because it allows you to use Javascript on both front-end and back-end. This way, every developer in your team can understand what&#x2019;s happening on the entire stack, and make changes if necessary.</p>
<h2 id="whyshouldyoulearnnodejs">Why should you learn Node.js?</h2>
<p>The two big mainstream uses are <strong>web application servers</strong> and <strong>asset pipeline automation</strong>.</p>
<p>Node.js uses an event-driven, non-blocking input/output model. Node.js scales flawlessly, and works perfectly for high-throughput server-side applications. Translated into simple English, this means that Node.js can be used to write applications that can handle large numbers of concurrent requests.</p>
<p>However, Node.js may not provide everything you need from a language out of the box. Many times you&apos;ll find yourself needing additional functionality, that you&apos;ll usually find available as a nicely maintained open source package. If you enjoy building things out of reusable blocks, then Node.js is definitely the for you. I sure do.</p>
<h3 id="nodejsgoodies">Node.js Goodies</h3>
<p>More reasons to learn Node.js are <a href="https://expressjs.com" rel="nofollow">Express</a>, <a href="https://www.npmjs.com" rel="nofollow">npm</a>, and <a href="https://webpack.js.org" rel="nofollow">Webpack</a>.</p>
<p>Express is a modular application server for Node.js that allows you to write scalable web applications. Express focuses on code reusability and development costs, giving you a strong foundation for your application. It&apos;s lightweight and super fast.</p>
<p>Node&apos;s package manager &quot;npm&quot; is a very powerful tool that can be used to share your code as packages. Not only that, but it allows you to reuse code written by other developers inside your own package, as dependencies. Just imagine having more than 600,000 packages at your fingertips.</p>
<p>Surely, everyone developer has heard at least once about Webpack by now. Webpack is a build tool that puts all of your assets, including CSS, Javascript, images, and even fonts, in a dependency graph. Webpack lets you use <code>require()</code> in your source code to point to local files, and decide how they&apos;re processed in your final bundle. If you&apos;re building a complex front-end application with many static assets that require processing, then Webpack will give you great benefits.</p>
<h3 id="stillnotconvinced">Still not convinced?</h3>
<p>Node.js and Javascript have been voted as the most popular development framework and programming in the <a href="https://insights.stackoverflow.com/survey/2018" rel="nofollow">2018 StackOverflow Developer Survey</a>.</p>
<p><img src="https://grozav.com/content/images/2020/01/Screenshot-2020-01-03-at-17.48.26.png" alt="Introduction to Node.js" loading="lazy"></p>
<p>For the sixth year in a row, Javascript is the most commonly used programming language. It&apos;s amazing how popular the Node.js stack has become and you shouldn&apos;t be missing out!</p>
<h2 id="whatyoualreadyneedtoknow">What you already need to know</h2>
<p>As you might have thought, there are some prerequisites before you can start learnng Node.js. When I started out, I had a strong programming and web development background, so the learning curve was almost non-existent.</p>
<ol>
<li>
<p><strong>Javascript</strong> &#x2015; Node.js is basically server side Javascript, so knowing Javascript is an absolute must. If you&apos;re familiar with other programming languages, learning Javascript will be fairly straightforward.</p>
</li>
<li>
<p><strong>HTTP</strong> &#x2015; If you&apos;re building web applications, you will need to understand HTTP client and server paradigm. You&apos;ll do just fine with some basic understanding and knowing what verbs like GET, POST, PUT, and DELETE are used for.</p>
</li>
<li>
<p><strong>Asynchronous Programming</strong> &#x2015; JavaScript is asynchronous in nature and so is Node.js. For example, Node.js will not wait for a HTTP request&apos;s response to arrive before executing the next line of code, and you&apos;ll rely heavily on callback functions.</p>
</li>
</ol>
<p>Besides these, I&apos;d recommend trying to understand what the concept of <strong>REST</strong> is and how it works, and reading up about the <strong>Node.js Event Loop</strong>. It might all seem like a lot to learn, but in reality they&apos;re simple concepts with fancy names.</p>
<h2 id="whatsnext">What&apos;s next?</h2>
<p>You&apos;ll learn how to create our own package and add dependencies to it later in this tutorial. Next, head over to <a href="https://grozav.com/installing-nodejs-the-right-way/">Installing Node.js the Right Way</a>, to install Node.js, write and run your first Node.js &quot;Hello world!&quot; program.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[To Web Development and Technology Lovers]]></title><description><![CDATA[I'm a creative overthinker. I love making my ideas come to life. It's the one thing I know best and the one thing I enjoy the most about my career choice.]]></description><link>https://grozav.com/a-blog-for-web-development-and-technology-lovers/</link><guid isPermaLink="false">5e00fb7c6d53224501c7a621</guid><category><![CDATA[Personal]]></category><dc:creator><![CDATA[Alex Grozav]]></dc:creator><pubDate>Thu, 19 Apr 2018 07:35:30 GMT</pubDate><media:content url="https://grozav.com/content/images/2020/01/66666649_10156753169612607_4813570075707572224_o.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://grozav.com/content/images/2020/01/66666649_10156753169612607_4813570075707572224_o.jpg" alt="To Web Development and Technology Lovers"><p><strong>Welcome to a place of creative thinking and ambitious ideas!</strong></p>
<p>I am Alex Grozav, and this article is the first piece of my little corner of expressivity. I&apos;m a self-thaught artist and developer who is writing open source projects to make the web a better place in his free time.</p>
<p><strong>I&apos;m overly passionate about what I do.</strong> It&apos;s not about what moderately exciting 9-to-5 job you have, whether you work at Google, Apple, or Microsoft. It&apos;s not even about how much you enjoy coding, or how much work you put into your tasks.</p>
<p>It&apos;s about what you do with your free time. It&apos;s about whether you ever felt the need to stay up until late at night, finishing an idea you had for this small project of yours, born out of dreams slightly bigger than you can carry. You&apos;re pretty sure it&apos;s not going to work this time either, yet you do it anyway, because that&apos;s who you are.</p>
<blockquote>
<p>I know you, because it takes one to know one.</p>
</blockquote>
<h2 id="imacreativeoverthinker">I&apos;m a creative overthinker</h2>
<p>I love making my ideas come to life. It&apos;s the one thing I know best and the one thing I enjoy the most about my career choice. <strong>I think, I design, I overthink, I code, and then, I test</strong>. To me, every web project is a beautiful mix of code, math and creativity, and having something that I created in its entirety, makes me always give it my best.</p>
<p>Unlike most people, I read mostly news about Technology and Web Development, the two things I&apos;m most enthusiastic about. I hate reading news about violence and useless celebrities, because there&apos;s an exaggerated amount of both.</p>
<p>I&apos;m the kind of person whose brain gets stupidly excited when it reads about breakthroughs in Medicine and Technology, because the thought that mankind is getting closer to the harmonious future we see in movies makes me feel good. I believe that, as developers, we&apos;re building towards a substantial part this future, one commit at a time.</p>
<h4 id="thisusedtobemyportfolio">This used to be my portfolio</h4>
<p>This site used to have countless hours of work featured in its pages. I used to sell HTML Templates on Themeforest and JavaScript plugins on CodeCanyon. This website is the place where I used to host and preview them.</p>
<p>Hundreds of sales, hundreds of comments, so little time to maintain all of them. When all you want to do is create something better every time you start writing code, you always end up enjoying your new project more than your old one.</p>
<h3 id="intheend">In the end</h3>
<p>I have turned it into a blog because sharing my code, designs, videos, reviews, creative thoughts and ideas will be far more valuable to my readers than anything else I made could have been.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>