<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nicolas Granja on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Granja on Medium]]></description>
        <link>https://medium.com/@nicogranja19?source=rss-55575816a453------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jLkTQjzAFoWv4PNtd7hj4g.jpeg</url>
            <title>Stories by Nicolas Granja on Medium</title>
            <link>https://medium.com/@nicogranja19?source=rss-55575816a453------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:30:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicogranja19/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Frontend Implementation]]></title>
            <link>https://medium.com/using-nestjs-sse-for-updating-front-end/frontend-implementation-344a05ff224e?source=rss-55575816a453------2</link>
            <guid isPermaLink="false">https://medium.com/p/344a05ff224e</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[sse]]></category>
            <dc:creator><![CDATA[Nicolas Granja]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 15:54:05 GMT</pubDate>
            <atom:updated>2023-06-06T15:54:05.354Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone! Building on our <a href="https://medium.com/using-nestjs-sse-for-updating-front-end/backend-implementation-cedd3801c210">previous article</a> on NestJS SSE, we are now moving forward to discuss how a VueJS application can consume those Server-Sent Events (SSE) that were emitted by a NestJS backend. This ensures an effective Event Driven Architecture (EDA), keeping your frontend seamlessly in sync with the backend.</p><p>Dealing with backend events can be fairly straightforward, especially when compared to the challenge of updating the frontend in real-time. This is where SSE becomes a lifesaver, providing an efficient mechanism to keep the frontend updated alongside backend events.</p><p>This article does not aim to compare this solution with others but rather focuses on sharing a hands-on implementation that has proven to be both functional and adaptable.</p><p>For those new to SSE or in need of a refresher, reviewing the <a href="https://docs.nestjs.com/techniques/server-sent-events">official NestJS documentation</a> and the <a href="https://github.com/nestjs/nest/tree/master/sample/28-sse">Github example</a> can be helpful. Once you&#39;re familiar with the basics, let&#39;s explore how to integrate SSEs into a VueJS app.</p><h3>Consuming SSE in VueJS</h3><p>Start by creating an instance of EventSource in your VueJS application. This instance should connect to the SSE endpoint set up in your NestJS backend. Here&#39;s an example within a Vue component:</p><pre>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      eventSource: null,<br>      messages: []<br>    }<br>  },<br>  created() {<br>    this.eventSource = new EventSource(&#39;http://localhost:8002/sse&#39;);<br>    this.eventSource.onmessage = (event) =&gt; {<br>      this.messages.push(&#39;New message: &#39; + event.data);<br>    };<br>  },<br>  beforeDestroy() {<br>    this.eventSource.close();<br>  },<br>}<br>&lt;/script&gt;</pre><p>The code above sets up an instance of EventSource when the Vue component is created and listens for incoming SSE messages. Each time a message is received, it&#39;s added to the messages array; This connection is then closed when the Vue component is destroyed to prevent memory leaks.</p><p>You can then utilize the messages array in your Vue template to display the received messages:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h2&gt;Messages from server:&lt;/h2&gt;<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(message, index) in messages&quot; :key=&quot;index&quot;&gt;{{ message }}&lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>The template renders a list of messages received from the server, providing a real-time user interface for your SSE events.</p><p>While this setup is rudimentary, it serves as a stepping stone for more intricate adaptations based on your project&#39;s specific needs. The beauty of this implementation lies in its simplicity and malleability; It can be tailored to handle different kinds of messages, add error handling, implement reconnect mechanisms, and more. The world of real-time updates is now at your fingertips.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=344a05ff224e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/using-nestjs-sse-for-updating-front-end/frontend-implementation-344a05ff224e">Frontend Implementation</a> was originally published in <a href="https://medium.com/using-nestjs-sse-for-updating-front-end">Using NestJS SSE (Server-Sent Events) for updating Front-end</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I triplicated my ads revenue doing a simple change on my web]]></title>
            <link>https://medium.com/@nicogranja19/how-i-triplicated-my-ads-revenue-doing-a-simple-change-on-my-web-f97ef6001499?source=rss-55575816a453------2</link>
            <guid isPermaLink="false">https://medium.com/p/f97ef6001499</guid>
            <category><![CDATA[revenue]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[ads]]></category>
            <category><![CDATA[profit]]></category>
            <category><![CDATA[website]]></category>
            <dc:creator><![CDATA[Nicolas Granja]]></dc:creator>
            <pubDate>Fri, 15 May 2020 16:25:15 GMT</pubDate>
            <atom:updated>2020-05-15T16:31:02.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VPEirtDt9L6quNBb" /><figcaption>Photo by <a href="https://unsplash.com/@frankbusch?utm_source=medium&amp;utm_medium=referral">Frank Busch</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’m going to explaining <strong>how I managed to triplicate my revenue from ads with a pretty simple change on my website that I believe most of you can replicate on your own sites</strong>.</p><p>Disclaimer: what I actually triplicated was the number of pages per session, which directly affected my ads revenue (you get paid for the number of impressions). To make it clearer, with the same number of visitors I triplicated the number of ads impression, and — before you ask — without adding more ads. Let’s see how I did it.</p><h3>Pleasant surprise.</h3><p>A couple of days ago I shared on the subreddit r/India (post <a href="https://www.reddit.com/r/india/comments/ghfme2/list_of_salaries_from_india_to_find_out_if_youre/">here</a>) my website knowyourworth.site. That drove a lot of traffic to my site, so I decided to take a look at the analytics. I found that I got 9k+ page views that day, but what it caught my attention was the number of Pages per Session: 7.3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdgraELawCK3cbiCHhxqbQ.png" /><figcaption>7.32 pages per session on May 11</figcaption></figure><p>Before that day (11th May), that metric was around 2.2, as you can see in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*jhaRI8wGtutMDfL2mlsKHw.png" /><figcaption>2.22 pages per session the week before</figcaption></figure><h3>Finding the reason</h3><p>The thing is, that the main page of my site is a big table where you can compare salaries filtering by location, education, experience, job title, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r7A0eZUZnRaWOWnoIVf_9A.png" /><figcaption>Salary comparison page with some filters applied.</figcaption></figure><p>Most of my visitors spent most of their time on that page, applying filters and browsing the data using the table pagination.</p><p>A lot of people were asking me if I could show the state of the filters in the URL, so they could copy it and share the search very easily.</p><p>So that&#39;s exactly what I did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*545FkEj7nMjdz80Fwzhz8g.png" /><figcaption>Filters in the URL</figcaption></figure><p>Once it was done, each time someone makes a search, the URL change (without refreshing the page, thanks to VueJs that reuse the component) but it actually counts as a new page, at least for google analytics. Therefore, <strong>with the same number of visitors, I get 3 times more page views.</strong></p><h3>The (not so) magical change</h3><p>It is debatable whether it is right to count it or not, but anyway I decided to take advantage of this, <strong>refreshing the ad each time the URL changed</strong> (I’ll keep the technical side of these changes aside, but if someone is interested just ask me), That&#39;s it, that&#39;s was the small change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjA2Ws8A7BmnDsbqJxeL5g.gif" /><figcaption>Ad refreshing each time a filter is applied</figcaption></figure><p>As you can see, it is a non-intrusive way to show more ads to the users but in a nicer way, not just throwing annoying ads all over the page.</p><p>I believe this kind of change could be useful for a lot of people that have a website like curated lists, job boards, etc, any page where the people spend a lot of time playing around with filters or something similar.</p><p>Well, that’s it, thanks for reading, I hope it was useful.</p><p>If you have some suggestions or ideas you can reach me out on <a href="https://twitter.com/ngranja19">twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f97ef6001499" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to migrate a VueJs project to NuxtJs in 7 steps.]]></title>
            <link>https://medium.com/@nicogranja19/how-to-migrate-a-vuejs-project-to-nuxtjs-in-7-steps-b340faf2977b?source=rss-55575816a453------2</link>
            <guid isPermaLink="false">https://medium.com/p/b340faf2977b</guid>
            <category><![CDATA[nuxt]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Nicolas Granja]]></dc:creator>
            <pubDate>Wed, 13 May 2020 01:42:57 GMT</pubDate>
            <atom:updated>2020-05-13T13:27:57.159Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to migrate a VueJs project to NuxtJs in 8 steps.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RtNJFaTVmSqxmpWz.png" /></figure><p>A couple of months ago I built a project using my favorite stack: VueJs + Buefy for the Front-End and NodeJs + Express for the Back-End. Some days later the website started to gain some traction, and I got a lot of traffic, but as most of you might know, a VueJs SPA is not a good option for SEO, therefore I decided to rebuild it completely with NuxtJS.</p><p>Since searching on the web I was not able to find any documentation or tutorial of how to do it, <strong>I’ll try to explain step by step what I did. I tell you in advance that it is very easy and just takes a c</strong>ouple of hours, <strong>but</strong> <strong>I’m assuming you have some idea of how nuxt works </strong>(if is not your case, I highly recommend you to read the official documentation)</p><p><a href="https://nuxtjs.org/">The Intuitive Vue Framework</a></p><h3>1. Create the nuxt project</h3><p>First of all, create the nuxt project using create-nuxt-app . You can get more information <a href="https://nuxtjs.org/guide/installation#using-code-create-nuxt-app-code-">here</a>.</p><h3>2. Copy your Stores</h3><p>If you aren’t using Vuex in your VueJs project you can skip this step. If so, you can pretty much copy your store files to the new /storefolder in your nuxt project. In my case, I was just using an index.js file. In case you had split your store in modules you can follow <a href="https://nuxtjs.org/guide/vuex-store">these instructions.</a></p><h3>3. Copy your Components</h3><p>First, we have to differentiate what is a component and what is a page. I don’t know which directory structure are you using, but I usually split my .vue files into two folders: views and components . It is pretty obvious, but in the views folder, I put those vue components (.vue files) that are pages, i.e: About, Home, FAQ, etc. While in the components I put those subcomponents that I reuse - and are included - in the views.</p><p>In case you are not following a structure similar to this one, you’ll have to make this distinction, and just copy the components - that are not pages - to the corresponding new /components folder.</p><h3>4. Create your Pages</h3><p>This time, you should rethink your pages and recreate each route following the convention specified by Nuxt.</p><blockquote><em>Nuxt.js automatically generates the </em><a href="https://github.com/vuejs/vue-router"><em>vue-router</em></a><em> configuration based on your file tree of Vue files inside the </em>pages<em> directory.</em></blockquote><p>If you don’t have any idea fo how to do this, I recommend you to read the following sections of the official Nuxt documentation: <a href="https://nuxtjs.org/guide/routing">Routing</a> and <a href="https://nuxtjs.org/guide/views">Views</a>.</p><h3>5. Change router-link for nuxt-link</h3><p>Once you have all your components and pages in the correct place, you will need to change all your router-link for nuxt-link. To see how nuxt is naming the routes you can check the automatically generated file inside /.nuxt/router.js</p><h3>6. Change the way you fetch the data from your servers</h3><p>You should go through all your new Pages, and refactor the way you were loading the data from your server.</p><blockquote><em>You may want to fetch data and render it on the server-side. Nuxt.js adds an </em>asyncData<em> method to let you handle async operations before initializing the component</em></blockquote><p>More information about asyncData <a href="https://nuxtjs.org/guide/async-data">here</a>.</p><p>If you were also fetching data in your components and you are trying to use asyncData, this is won’t work, because components don’t have an asyncData method. But don’t worry, there are two solutions for this:</p><ol><li>Make the API call in the mounted hook. Take in count that with this way the server-side rendering won’t work</li><li>Make the API call in the asyncData or fetch methods of the page component and pass the data as props to the sub-components.</li></ol><h3>7. Add your plugins</h3><p>Go to your main.js file of your VueJs Project, and identify which plugins you are using. Then set up all your plugins following the instructions <a href="https://nuxtjs.org/guide/plugins#vue-plugins">here</a>.</p><h3>8. Add the external resources</h3><p>Finally, If you are using some external resources in the index.html file of your VueJs project, like stylesheets or an external js script, you can include them in the head object of nuxt.config.js. See more info <a href="https://nuxtjs.org/faq#global-settings">here</a>.</p><p>After doing all those changes, you can see how it looks like my new NuxtJs project compared to the old VueJs (pretty similar right?).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*7tqhUGp6xnqVJsgBSaPH-g.png" /><figcaption>Directory Structure of my VueJs app (left) and the new NuxtJs (right)</figcaption></figure><p>If you are wondering which was the project that I rebuilt with NuxtJs you can see it here: <a href="https://knowyourworth.site/">https://knowyourworth.site</a></p><p><a href="https://knowyourworth.site/">Find out if you are being paid fairly - KnowYourWorth</a></p><p>Let me know if you have any question or reach me out on twitter <a href="https://twitter.com/ngranja19">https://twitter.com/ngranja19</a></p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b340faf2977b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>