<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anish Ghimire</title>
    <description>The latest articles on DEV Community by Anish Ghimire (@anishghimire862).</description>
    <link>https://dev.to/anishghimire862</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F835870%2Fdbf63d98-95f1-43da-af1b-6a93f4599371.jpg</url>
      <title>DEV Community: Anish Ghimire</title>
      <link>https://dev.to/anishghimire862</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anishghimire862"/>
    <language>en</language>
    <item>
      <title>Cat Character Image - Generated Using Google's Nano Banana</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Wed, 14 Jan 2026 10:03:32 +0000</pubDate>
      <link>https://dev.to/anishghimire862/cat-character-image-generated-using-googles-nano-banana-2085</link>
      <guid>https://dev.to/anishghimire862/cat-character-image-generated-using-googles-nano-banana-2085</guid>
      <description>&lt;p&gt;Meet our new cat character 🐱✨&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sbrymm2iuolb4tc6gc2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sbrymm2iuolb4tc6gc2.jpeg" alt="Cat Character Image - Generated Using Google's Nano Banana" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lovable, expressive, and built for storytelling, happy moments and real emotional depth.&lt;/p&gt;

&lt;p&gt;Generated using Google’s Nano Banana with a custom character prompt, designed for reuse across multiple videos.&lt;/p&gt;

&lt;p&gt;What should we name this little legend? 👀🎬&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>nanobanana</category>
      <category>llm</category>
    </item>
    <item>
      <title>Cloudflare Outage - 18th November 2025</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Tue, 18 Nov 2025 17:38:53 +0000</pubDate>
      <link>https://dev.to/anishghimire862/cloudflare-outage-18th-november-2025-1gp5</link>
      <guid>https://dev.to/anishghimire862/cloudflare-outage-18th-november-2025-1gp5</guid>
      <description>&lt;p&gt;One month after the major AWS &lt;a href="https://thundergolfer.com/blog/aws-us-east-1-outage-oct20" rel="noopener noreferrer"&gt;outage&lt;/a&gt;, today the internet experienced an outage from &lt;a href="https://www.cloudflare.com/en-gb/" rel="noopener noreferrer"&gt;Cloudflare&lt;/a&gt;, which provides a range of internet services.&lt;/p&gt;

&lt;p&gt;We really don’t realize how many web applications depend on Cloudflare until the service provider stops working. From DNS management to deployments, Cloudflare has reached the point where it can power the complete web infrastructure. Some of the downtime detectors that were supposed to alert site owners about the downtime were impacted as well.&lt;/p&gt;

&lt;p&gt;But the good thing is, &lt;a href="https://x.com/dok2001" rel="noopener noreferrer"&gt;Dane Knecht&lt;/a&gt;, the CTO of Cloudflare, has confirmed on &lt;a href="https://x.com/dok2001/status/1990791419653484646" rel="noopener noreferrer"&gt;X&lt;/a&gt; that the issue has been resolved.&lt;/p&gt;

&lt;p&gt;Dane writes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I won’t mince words: earlier today we failed our customers and the broader Internet when a problem in @Cloudflare network impacted large amounts of traffic that rely on us. The sites, businesses, and organizations that rely on Cloudflare depend on us being available and I apologize for the impact that we caused.&lt;/p&gt;

&lt;p&gt;Transparency about what happened matters, and we plan to share a breakdown with more details in a few hours. In short, a latent bug in a service underpinning our bot mitigation capability started to crash after a routine configuration change we made. That cascaded into a broad degradation to our network and other services. This was not an attack.&lt;/p&gt;

&lt;p&gt;That issue, impact it caused, and time to resolution is unacceptable. Work is already underway to make sure it does not happen again, but I know it caused real pain today. The trust our customers place in us is what we value the most and we are going to do what it takes to earn that back.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The apologetic and regretful tweet clearly shows Dane’s seriousness and sense of accountability.&lt;/p&gt;

&lt;p&gt;Such outages impact millions of users, ranging from individuals to businesses. At times, such situations are unavoidable, and what’s important is how we handle these tough periods and our willingness to fix the underlying issues.&lt;/p&gt;

&lt;p&gt;Dane further said that the team was able to resolve the issue, which was their first priority, and are now monitoring the services to ensure everything is fully operational. They also plan to share a complete walkthrough of what went wrong.&lt;/p&gt;

&lt;p&gt;That's all for this blog. Stay tuned, and we'll come back with another blog featuring an in-depth analysis of what caused the incident at Cloudflare.&lt;/p&gt;

</description>
      <category>cloudflare</category>
    </item>
    <item>
      <title>AI Agents - Introduction and Customer Support AI Agent Example</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Tue, 14 Oct 2025 15:04:47 +0000</pubDate>
      <link>https://dev.to/anishghimire862/ai-agents-introduction-and-customer-support-ai-agent-example-531e</link>
      <guid>https://dev.to/anishghimire862/ai-agents-introduction-and-customer-support-ai-agent-example-531e</guid>
      <description>&lt;p&gt;&lt;a href="https://sarvalekh.com/blog/an-introduction-to-artificial-intelligence" rel="noopener noreferrer"&gt;Artificial Intelligence&lt;/a&gt; is growing at a very fast pace. The surge in transformer-based models like &lt;a href="https://openai.com/index/gpt-4/" rel="noopener noreferrer"&gt;GPT&lt;/a&gt;, &lt;a href="https://qwen.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;Qwen&lt;/a&gt; and &lt;a href="https://gemini.google.com/app" rel="noopener noreferrer"&gt;Gemini&lt;/a&gt;, along with open-source innovations, has accelerated advancements in generative AI much faster than in other branches of AI. AI Agents have played a vital role in the growth and adoption of AI.&lt;/p&gt;

&lt;p&gt;In this blog, we'll discuss the following topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI Agent Introduction&lt;/li&gt;
&lt;li&gt;Types of AI Agents&lt;/li&gt;
&lt;li&gt;Connection of AI Agents with Generative AI&lt;/li&gt;
&lt;li&gt;Why are AI Agents required?&lt;/li&gt;
&lt;li&gt;An Example of AI Agent In Customer Support&lt;/li&gt;
&lt;li&gt;Customer Support AI Agent Implementation with NodeJS and Ollama&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is an AI Agent?
&lt;/h2&gt;

&lt;p&gt;An Artificial Intelligence (AI) &lt;a href="https://github.com/resources/articles/ai/what-are-ai-agents" rel="noopener noreferrer"&gt;Agent&lt;/a&gt; is a software program that can perceive its environment, make decisions, and autonomously perform tasks to achieve predefined or dynamic goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of AI Agents
&lt;/h2&gt;

&lt;p&gt;AI agents can be categorized into four &lt;a href="https://www.digitalocean.com/resources/articles/types-of-ai-agents#types-of-ai-agents" rel="noopener noreferrer"&gt;types&lt;/a&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  Reactive Agents
&lt;/h3&gt;

&lt;p&gt;Reactive agents react to immediate stimuli without memory of past interactions. Examples include autonomous vacuum cleaners and traffic light systems that change based on a set timer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Goal-Based Agents
&lt;/h3&gt;

&lt;p&gt;Goal-based agents plan actions to achieve specific goals. They modify their strategies as needed to reach their desired outcome. Autonomous vehicles, game-playing agents, etc., are examples of goal-based agents.&lt;/p&gt;

&lt;h3&gt;
  
  
  Utility-Based Agents
&lt;/h3&gt;

&lt;p&gt;Utility-based agents aim to maximize overall utility or value. They seek to optimize their performance. A self-driving car can be an example of a utility-based agent if it makes decisions that reduce travel time and fuel consumption.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning Agents
&lt;/h3&gt;

&lt;p&gt;Learning agents learn from their environment and improve their performance through interaction. Learning agents are not explicitly programmed to handle every scenario.&lt;/p&gt;

&lt;p&gt;Recommendation systems, such as those of Netflix and YouTube, are examples of learning agents. They learn from user behavior and adapt to changes over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connection of AI Agents with Generative AI (Gen AI)
&lt;/h2&gt;

&lt;p&gt;Before diving deeper into agentic AI or AI agents, let's first understand their connection with &lt;a href="https://sarvalekh.com/blog/an-introduction-to-generative-ai" rel="noopener noreferrer"&gt;Generative AI&lt;/a&gt; (Gen AI).&lt;/p&gt;

&lt;p&gt;Generative AI primarily refers to AI models that generate new content based on a given prompt and their training data. AI agents go beyond Gen AI by making decisions and taking actions autonomously.&lt;/p&gt;

&lt;p&gt;AI agents leverage Gen AI models for intelligence and utilize external tools such as APIs, databases, and other automation systems to complete tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are AI Agents required?
&lt;/h2&gt;

&lt;p&gt;AI agents help bridge the gap between what an LLM has been trained on and the domain-specific knowledge required to solve a particular type of problem.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom Knowledge Access: An AI agent can be equipped with a custom knowledge base.&lt;/li&gt;
&lt;li&gt;Tool Integration: AI agents can automate tasks beyond text generation, such as querying databases and retrieving real-time data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI agents are required when the system needs to be adaptable, configurable, contextually aware, capable of accessing domain-specific knowledge, and able to perform or automate certain tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  An Example of AI Agent In Customer Support
&lt;/h2&gt;

&lt;p&gt;Consider a customer support AI Agent with its own knowledge base. For queries, the agent first checks its knowledge base. If relevant resources are found, the information is passed on to the LLM (like Qwen or Gemini) to generate a response.&lt;/p&gt;

&lt;p&gt;In cases where there is no relevant information in the knowledge base, the AI agent responds using the LLM based solely on what it has been trained on.&lt;/p&gt;

&lt;p&gt;In the above example, the AI agent is making the decision to use different methods (its own knowledge base or LLM) based on the information it has, which is a key characteristic of an AI agent - it takes actions autonomously to complete a task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customer Support AI Agent Implementation with NodeJS and Ollama
&lt;/h2&gt;

&lt;p&gt;Theory can be boring, so without wasting much time, let's jump straight into a demo project.&lt;/p&gt;

&lt;p&gt;In this project, we will set up an intelligent customer support agent with its custom knowledge base, which will be responsible for assisting users with support-related tasks.&lt;/p&gt;

&lt;p&gt;For demonstration purposes, we’ll set up a NodeJS project and store the knowledge base in a JSON file. We'll use the Qwen2.5 LLM model through Ollama.&lt;/p&gt;

&lt;p&gt;The NodeJS program serves as the middleware between the AI model and the end user.&lt;/p&gt;

&lt;p&gt;The below-mentioned knowledge.json file is an example of a knowledge base for the demonstration in this blog.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  ...,
  "Change Password": "To change your password, please navigate to https://sarvalekh.com/change-password",
  "Activate Account": "To activate your account, you need to upload an identity card by navigating to https://sarvalekh.com/activate"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The knowledge base can come in various formats, such as a site's FAQs, databases, images, audio, video, PDFs, and more. Since LLMs are primarily designed to work with text-based data, additional processing steps are required when the knowledge base is not in text format.&lt;/p&gt;

&lt;p&gt;We first read the content of the knowledge base from the &lt;code&gt;knowledge.json&lt;/code&gt; file. The knowledge base contains domain-specific information that is generally not included in the training data of an LLM or may not be available on the internet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let knowledgeBase = {}
fs.readFile('knowledge.json', 'utf8', (err, data) =&amp;gt; {
  if (err) {
    console.error('Error reading knowledge base:', err)
  } else {
    knowledgeBase = JSON.parse(data)
  }
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the knowledge base is loaded, we handle user queries and interact with the Ollama API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function runQuery(query) {
  const knowledgeContent = JSON.stringify(knowledgeBase)
  const prompt = `
  You are an intelligent customer support agent. Your goal is to assist users by providing accurate, clear, and concise answers based on the knowledge base you have access to.

  Here is the knowledge base:
  ${knowledgeContent}

  Use this knowledge to answer the user's query as accurately as possible. If the query is unclear or there is no direct answer in the knowledge base, inform the user politely and suggest alternatives or ask for clarification.

  The user has asked: "${query}"

  Please provide a helpful response.
  `

  try {
    const response = await axios.post('http://localhost:11434/api/generate', {
      model: 'qwen2.5',
      prompt: prompt,
      temperature: 0.7,
      stream: false,
    })

    return response.data?.response || 'Answer not found.'
  } catch (error) {
    console.error('Error querying Ollama:', error)
    return 'Sorry, there was an error processing your request.'
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The knowledge base is converted into string format and included in the prompt. The prompt guides the LLM to act as a customer support agent and use the knowledge base to answer the user’s query.&lt;/p&gt;

&lt;p&gt;Once the model completes processing the query and a response is generated, we return the generated response.&lt;/p&gt;

&lt;p&gt;We’ve come to the final part of the code, where we will set up the (/query) API endpoint that listens for POST requests, processes the user's query, and then returns the response from the LLM to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/query', async (req, res) =&amp;gt; {
  const query = req.body.query.trim()

  const response = await runQuery(query)
  res.json({ response })
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a POST request is sent to the (/query) endpoint with I am unable to activate my account the agent responds with a reply generated using the domain-specific knowledge base.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST http://localhost:3000/query \
     -H "Content-Type: application/json" \
     -d '{"query": "I am unable to activate my account.."}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo1eu658jsav56pfv8w4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo1eu658jsav56pfv8w4.png" alt="Customer Support AI Agent" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The source code for the demo project can be found &lt;a href="https://github.com/anishghimire862/ai-agent-example" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With this, we’ve come to the end of the blog. We demonstrated a basic customer support agent using Ollama and NodeJS. The possibilities are unlimited, but this should serve as a good starting point for anyone wanting to learn about Artificial Intelligence.&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>An introduction to Generative Artificial Intelligence (Gen AI)</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Sat, 05 Apr 2025 12:16:16 +0000</pubDate>
      <link>https://dev.to/anishghimire862/an-introduction-to-generative-artificial-intelligence-gen-ai-c8i</link>
      <guid>https://dev.to/anishghimire862/an-introduction-to-generative-artificial-intelligence-gen-ai-c8i</guid>
      <description>&lt;p&gt;In our previous &lt;a href="https://dev.to/anishghimire862/an-introduction-to-artificial-intelligence-22p6"&gt;blog&lt;/a&gt;, we discussed the introduction to Artificial Intelligence, AI’s brief history, types, branches, and examined how the different branches of AI work together through a real-world example of virtual assistants like Siri and Alexa.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Generative AI (Gen AI)?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://research.ibm.com/blog/what-is-generative-AI" rel="noopener noreferrer"&gt;Generative AI&lt;/a&gt; or Gen AI is a branch of AI that is focused on generating content. It can generate content like text, images, code, audio, video, and more for a given prompt. Gen AI generates content based on patterns it has learned from large datasets.&lt;/p&gt;

&lt;p&gt;Gen AI has various applications across different domains. Text generation is one of the key applications of Gen AI. The following are some other important applications of Gen AI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text Generation&lt;/li&gt;
&lt;li&gt;Image Generation&lt;/li&gt;
&lt;li&gt;Video Generation&lt;/li&gt;
&lt;li&gt;Code Generation&lt;/li&gt;
&lt;li&gt;Music and Audio Generation&lt;/li&gt;
&lt;li&gt;3D Model Generation&lt;/li&gt;
&lt;li&gt;AI-Powered Chatbots&lt;/li&gt;
&lt;li&gt;AI-Powered Writing and Design Tools&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Rise of Generative AI (Gen AI)
&lt;/h2&gt;

&lt;p&gt;The biggest breakthrough of Generative AI can be attributed to the research paper &lt;a href="https://arxiv.org/abs/1706.03762" rel="noopener noreferrer"&gt;Attention is All You Need&lt;/a&gt;, introduced in 2017 by Google scholars. They proposed a new simple network architecture, the Transformer.&lt;/p&gt;

&lt;p&gt;Besides the new architecture, the availability of large datasets, improved computing power, corporate funding, and businesses finding profitable and practical use cases have all contributed to the rise and explosive growth of Gen AI in recent years.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transformer
&lt;/h2&gt;

&lt;p&gt;A &lt;a href="https://huggingface.co/learn/llm-course/en/chapter1/4" rel="noopener noreferrer"&gt;transformer&lt;/a&gt; is a deep learning model architecture that allows processing entire sequences of text in parallel, which makes them more efficient than previous architectures like RNNs and LSTMs. GPT-3, GPT-4, BERT, and DALL-E are all built on transformer models.&lt;/p&gt;

&lt;p&gt;The self-attention mechanism allows the model to focus on relevant words in a sentence, regardless of their position.&lt;/p&gt;

&lt;p&gt;In the sentence “The cat sat on the mat because it was comfortable,” a traditional model struggles to understand that “it” refers to “the mat,” but a Transformer assigns attention scores to different words, helping it understand relationships more effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Generative AI (Gen AI) work?
&lt;/h2&gt;

&lt;p&gt;Gen AI generates new content by learning patterns from large amounts of data. Gen AI goes through two training phases:&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-training
&lt;/h3&gt;

&lt;p&gt;The Gen AI model is trained on large datasets.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fine-tuning
&lt;/h3&gt;

&lt;p&gt;After pre-training, the model is refined using domain-specific datasets and human feedback. ChatGPT was fine-tuned with Reinforcement Learning from Human Feedback (RLHF) to provide more human-like responses.&lt;/p&gt;

&lt;p&gt;Once trained, the AI processes user prompts, applies its learned knowledge, and, using Transformer architecture, generates new text, images, or code in real time.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Machine Learning (ML), Neural Networks (NNs), and Natural Language Processing (NLP) Work Together with Generative AI
&lt;/h2&gt;

&lt;p&gt;Gen AI relies on other branches of AI, such as Machine Learning (ML), Neural Networks (NNs), and Natural Language Processing (NLP), to function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr1b5qbb5kuh6p25u5sz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr1b5qbb5kuh6p25u5sz.png" alt="Example of Generative AI's working flow" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Machine Learning (ML)
&lt;/h3&gt;

&lt;p&gt;Gen AI models are trained using machine learning models to learn patterns from large datasets in order to create meaningful content.&lt;/p&gt;

&lt;p&gt;It learns patterns, grammars, and how words are structured to generate a response.&lt;/p&gt;

&lt;h3&gt;
  
  
  Neural Networks (NNs)
&lt;/h3&gt;

&lt;p&gt;Gen AI uses neural networks, particularly deep learning, to identify patterns, interpret data, and make decisions.&lt;/p&gt;

&lt;p&gt;Large language models like GPT-4 use transformers to process input and predict the next best word based on its training.&lt;/p&gt;

&lt;h3&gt;
  
  
  Natural Language Processing (NLP)
&lt;/h3&gt;

&lt;p&gt;Gen AI uses natural language processing to understand and structure language.&lt;/p&gt;

&lt;p&gt;NLP techniques help the model understand the intent behind the user’s prompt, understand the structure of the language, grammar, meaning, and generate relevant, grammatically correct, and human-like responses.&lt;/p&gt;

&lt;p&gt;To summarize, machine learning helps the model learn from a large dataset, neural networks help process the prompt and generate content, and natural language processing ensures language understanding and structure.&lt;/p&gt;

&lt;p&gt;That's all for this blog! I hope you found it helpful as you begin your journey into Gen AI. We’ll be back soon with more content, so stay tuned!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>genai</category>
    </item>
    <item>
      <title>An introduction to Artificial Intelligence</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Thu, 20 Mar 2025 04:12:20 +0000</pubDate>
      <link>https://dev.to/anishghimire862/an-introduction-to-artificial-intelligence-22p6</link>
      <guid>https://dev.to/anishghimire862/an-introduction-to-artificial-intelligence-22p6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Artificial intelligence (AI)&lt;/strong&gt; refers to computer systems or machines designed to simulate human-like intelligence, enabling them to perform tasks such as reasoning, problem-solving, learning, adaptation, perception, and decision-making.&lt;/p&gt;

&lt;p&gt;AI systems use algorithms, data, and machine learning (a process of iterative improvement) to autonomously adapt, improve, and execute tasks. AI autonomy means an AI can operate, make decisions, and complete tasks with varying levels of human supervision .&lt;/p&gt;

&lt;h2&gt;
  
  
  Brief history of Artificial intelligence (AI)
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.ibm.com/think/topics/artificial-intelligence" rel="noopener noreferrer"&gt;history of AI&lt;/a&gt; dates back to the early 1900s. From the birth of AI, its maturation, the AI boom, the AI winter, AI agents, and up to the present day, we have come a long way.&lt;/p&gt;

&lt;p&gt;AI development experienced rises and falls multiple times; dozens of companies failed, and it was widely believed that the technologies were not viable. During this period, AI was primarily used behind the scenes.&lt;/p&gt;

&lt;p&gt;The current buzz and success surrounding AI can be attributed to advanced technologies, powerful processors and hardware like GPUs, improved algorithms, and the availability of large datasets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Narrow AI vs. General AI
&lt;/h2&gt;

&lt;p&gt;There are various &lt;a href="https://www.simplilearn.com/tutorials/artificial-intelligence-tutorial/types-of-artificial-intelligence" rel="noopener noreferrer"&gt;types of AI&lt;/a&gt;, but in this blog, we'll focus on two: Narrow AI and General AI&lt;/p&gt;

&lt;h3&gt;
  
  
  Narrow AI (Weak AI)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Narrow AI (or weak AI)&lt;/strong&gt; is a type of artificial intelligence specialized in performing a limited set of tasks . Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Voice assistants like Siri or Alexa.&lt;/li&gt;
&lt;li&gt;Recommendation systems (e.g., YouTube, Netflix).&lt;/li&gt;
&lt;li&gt;Tesla’s driver-assist system (Autopilot).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These systems excel at specific tasks but lack general intelligence.&lt;/p&gt;

&lt;h3&gt;
  
  
  General AI (AGI or Strong AI)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Artificial General Intelligence (AGI)&lt;/strong&gt;, also called &lt;strong&gt;Strong AI&lt;/strong&gt;, is a theoretical form of AI that would possess human-level intelligence. It could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reason, solve problems, and perform any intellectual task a human can do .&lt;/li&gt;
&lt;li&gt;Learn new skills dynamically, similar to human adaptability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AGI remains hypothetical, and no real-world examples exist today . Current AI systems are all Narrow AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Artificial Intelligence (AI) work?
&lt;/h2&gt;

&lt;p&gt;AI works by simulating human intelligence in computer systems or machines. It makes use of algorithms, data, and computational power to simulate human-like intelligence, learn, solve problems, make decisions, recognize patterns, and more.&lt;/p&gt;

&lt;p&gt;To understand how AI works, let's look at some of the foundational elements that make AI function:&lt;/p&gt;

&lt;h3&gt;
  
  
  Data
&lt;/h3&gt;

&lt;p&gt;AI relies on large datasets. The data is used for training and decision-making. The quality and quantity of data directly influence the performance of AI models.&lt;/p&gt;

&lt;p&gt;The data can be either structured, such as data from databases, or unstructured, such as images, audio, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Algorithm
&lt;/h3&gt;

&lt;p&gt;Algorithms are sets of instructions or rules that determine how AI should process the data and learn from it. Some examples include supervised learning, unsupervised learning, and reinforcement learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Neural Networks
&lt;/h3&gt;

&lt;p&gt;Neural networks are computational models inspired by the human brain. They are designed to make decisions in a manner similar to the human brain. Neural networks rely on training data to learn and improve their accuracy over time. They are widely used in deep learning and natural language processing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;Training in the context of AI refers to teaching an AI model to perform a specific task or set of tasks. Training involves a process of trial and error, and as training progresses, the AI models need to be fine-tuned.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;

&lt;p&gt;Inference is the stage where AI performs its intended task based on what it has learned.&lt;/p&gt;

&lt;p&gt;Now that we've discussed how AI works by using data, algorithms, neural networks, training, and inference, let's dive deeper into three key &lt;a href="https://www.aiacceleratorinstitute.com/what-are-the-top-7-branches-of-artificial-intelligence/" rel="noopener noreferrer"&gt;branches of AI&lt;/a&gt; where these different components of an AI system come together: Machine Learning (ML), Natural Language Processing (NLP), and Neural Networks (NN).&lt;/p&gt;

&lt;h2&gt;
  
  
  Branches of Artificial Intelligence (AI)
&lt;/h2&gt;

&lt;p&gt;AI is a vast and multifaceted field, which is why the need for different branches of AI arises. Each branch focuses on solving specific types of challenges using particular techniques, tools, and approaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Machine Learning (ML)
&lt;/h2&gt;

&lt;p&gt;Machine Learning (ML) is a branch of AI that focuses on enabling computer systems or machines to learn from data without being explicitly programmed. ML allows systems to simulate the way humans learn, perform tasks autonomously, and improve their performance through experience and exposure to large datasets.&lt;/p&gt;

&lt;p&gt;There are three major categories of machine learning methods: supervised learning, unsupervised learning, and reinforcement learning.&lt;/p&gt;

&lt;p&gt;Neural networks, linear regression, logistic regression, clustering, and decision trees are some of the commonly used machine learning algorithms.&lt;/p&gt;

&lt;p&gt;For instance, recommendation systems (such as those used by Netflix, YouTube, etc.) use ML to analyze user behavior (data), apply algorithms to find patterns, and suggest personalized recommendations (inference).&lt;/p&gt;

&lt;h2&gt;
  
  
  Neural Networks (NN)
&lt;/h2&gt;

&lt;p&gt;A neural network (NN) is a machine learning model inspired by the human brain, consisting of interconnected nodes (neurons) that process information through weighted connections and layers. Neural networks are a part of machine learning and enable tasks such as pattern recognition, speech processing, and decision-making.&lt;/p&gt;

&lt;p&gt;A basic neural network typically consists of three layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input Layer : Receives the raw data&lt;/li&gt;
&lt;li&gt;Hidden Layer(s) : Processes the data&lt;/li&gt;
&lt;li&gt;Output Layer : Provides the final result&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Deep Learning (DL)
&lt;/h3&gt;

&lt;p&gt;Deep Learning is a specialized subfield of neural networks. Deep Learning and neural networks are often used interchangeably, which can lead to confusion. The word &lt;strong&gt;deep&lt;/strong&gt; in deep learning refers to the depth of layers in a neural network.&lt;/p&gt;

&lt;p&gt;A neural network that has only two to three hidden layers is considered a basic neural network, while a neural network with more than three layers is referred to as a deep learning model.&lt;/p&gt;

&lt;p&gt;For example, self-driving cars use neural networks to process visual data (data), recognize objects, pedestrians, traffic signs, and other vehicles (training), and make real-time traffic decisions (inference).&lt;/p&gt;

&lt;h2&gt;
  
  
  Natural Language Processing (NLP)
&lt;/h2&gt;

&lt;p&gt;Natural Language Processing (NLP) is a branch of AI that focuses on enabling computer systems or machines to understand and communicate in human language.&lt;/p&gt;

&lt;p&gt;NLP allows computer systems or machines to recognize, understand, interpret, and generate human language in a way that is both meaningful and useful. NLP combines computational linguistics, machine learning, and deep learning models to process human language.&lt;/p&gt;

&lt;p&gt;Some approaches to NLP include Supervised NLP, Unsupervised NLP, Natural Language Understanding (NLU), and Natural Language Generation (NLG).&lt;/p&gt;

&lt;p&gt;NLP is being utilized to automate various tasks, such as processing and analyzing large datasets, running chatbots, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Machine Learning (ML), Neural Networks (NNs), and Natural Language Processing (NLP) Work Together
&lt;/h2&gt;

&lt;p&gt;Now that we've explored machine learning, neural networks, and natural language processing as key branches of AI, let's see how they all come together in a real-world application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04ogzozv6lt478h64f8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04ogzozv6lt478h64f8d.png" alt="Example of virtual assistant like Siri or Alexa" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make the picture clearer, let's take the example of a virtual assistant like &lt;a href="https://www.apple.com/siri/" rel="noopener noreferrer"&gt;Siri&lt;/a&gt; or &lt;a href="https://alexa.com/" rel="noopener noreferrer"&gt;Alexa&lt;/a&gt; answering a question about the weather.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: You ask Siri, "Hey Siri, what's the weather like today?"&lt;/p&gt;

&lt;p&gt;Once you ask Siri about the weather, it uses NLP to convert your spoken words into text. This part is called speech recognition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Understanding the text&lt;/p&gt;

&lt;p&gt;The system behind Siri uses NLP and neural networks to understand what you are asking.&lt;/p&gt;

&lt;p&gt;NLP breaks down the sentence into smaller parts, identifying that you are asking about the weather and that you want information for today.&lt;/p&gt;

&lt;p&gt;Neural networks help in recognizing patterns. For instance, they might identify that the word "weather" is associated with querying an external weather API.&lt;/p&gt;

&lt;p&gt;Modern NLP often uses transformers (a type of neural network, such as BERT or GPT) to understand the context and relationships between words.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Learning from past interactions&lt;/p&gt;

&lt;p&gt;The role of ML comes into play when deciding what to do next based on what it has learned. The virtual assistant uses ML to improve over time by learning from past interactions. The ML algorithms analyze patterns in user queries to predict the best response or action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Fetching the weather data&lt;/p&gt;

&lt;p&gt;The system fetches the weather information for today. A neural network might be used to process the query and decide which API to call. For example, the system sends a request to a weather API and retrieves the current temperature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Generating a response&lt;/p&gt;

&lt;p&gt;Once the weather API provides the current weather details, such as &lt;code&gt;(23, "degrees", "celsius", ["sunny", "comfortable"])&lt;/code&gt;, the system combines the data to form a grammatically correct sentence structure.&lt;/p&gt;

&lt;p&gt;For example, it might form a sentence like: &lt;code&gt;The weather today is sunny and comfortable with a high of 23 degrees Celsius&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here, NLP helps to generate the response, and neural networks ensure the response is contextually appropriate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Converting Text to Speech&lt;/p&gt;

&lt;p&gt;As a final step, the virtual assistant speaks the response back to you. NLP converts the generated response into speech using a process called Text-To-Speech (TTS). Neural networks are often used in TTS to make the voice sound more natural and human-like.&lt;/p&gt;

&lt;p&gt;That's it! We have come to the end of the introductory blog on AI. I hope the blog will be helpful for anyone who wants to begin their journey of learning about AI. We'll be coming up with more exciting content on AI soon!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>nlp</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Bun Runtime - Building Nuxt app with Bun (Part 2)</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Mon, 15 Apr 2024 12:27:36 +0000</pubDate>
      <link>https://dev.to/anishghimire862/bun-runtime-building-nuxt-app-with-bun-part-2-5c3c</link>
      <guid>https://dev.to/anishghimire862/bun-runtime-building-nuxt-app-with-bun-part-2-5c3c</guid>
      <description>&lt;p&gt;In our previous &lt;a href="https://dev.to/anishghimire862/bun-runtime-introduction-part-1-c1p"&gt;blog&lt;/a&gt; on the &lt;a href="https://bun.sh/" rel="noopener noreferrer"&gt;Bun Runtime&lt;/a&gt; series we briefly discussed Bun runtime, its installation process, scaffolding new projects, and the way to run them.&lt;/p&gt;

&lt;p&gt;In this part, we’ll be setting up a new &lt;a href="https://nuxt.com/" rel="noopener noreferrer"&gt;Nuxt&lt;/a&gt; application with Bun.&lt;/p&gt;

&lt;p&gt;Bun supports Nuxt out of the box so we can use &lt;code&gt;nuxi cli&lt;/code&gt; to initialize a Nuxt project.&lt;/p&gt;

&lt;p&gt;Run the following command to initialize a new Nuxt project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunx nuxi init my-nuxt-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiiwg3haizab2na9uxl5w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiiwg3haizab2na9uxl5w.png" alt="Initialize Nuxt App" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command is throwing &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node&lt;/a&gt; version incompatibility errors during the initialization since the project setup is trying to use NodeJS instead of Bun. In this case, we can set the target to bun and re-run the command.&lt;/p&gt;

&lt;p&gt;To setup the project using Bun add &lt;code&gt;--bun&lt;/code&gt; flag just after &lt;code&gt;bunx&lt;/code&gt; and run the command again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunx -–bun nuxi init my-nuxt-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa80lyy9lrzkouacn8amt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa80lyy9lrzkouacn8amt.png" alt="Initialize Nuxt app with Bun" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we’ve set the project you can navigate to the new project directory and run the &lt;code&gt;bun –bun run dev&lt;/code&gt; to start the development server.&lt;/p&gt;

&lt;p&gt;Make sure to pass the target as bun with flag &lt;code&gt;--bun&lt;/code&gt; otherwise, Bun will spin up a node process to execute the program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvx8nsjgke9nm5lk6b7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvx8nsjgke9nm5lk6b7t.png" alt="Nuxt Dev Server" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our dev server is already up and running so we can visit &lt;code&gt;localhost:3000&lt;/code&gt; to see our Nuxt app running behind the new Bun runtime. ;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1y7ooo6tw5qx9c3eawf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1y7ooo6tw5qx9c3eawf.png" alt="Nuxt App Demo" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we’ve set a Nuxt project using Bun. I hope this blog helps you with setting up a Nuxt app using Bun.&lt;/p&gt;

&lt;p&gt;In the next part of this blog, we'll be deploying the Nuxt app we created using a server and deployment management tool called &lt;a href="https://cleavr.io" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt;, with Bun as the runtime.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>cleavr</category>
    </item>
    <item>
      <title>Bun Runtime - Introduction (Part 1)</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Sun, 14 Apr 2024 06:02:41 +0000</pubDate>
      <link>https://dev.to/anishghimire862/bun-runtime-introduction-part-1-c1p</link>
      <guid>https://dev.to/anishghimire862/bun-runtime-introduction-part-1-c1p</guid>
      <description>&lt;p&gt;&lt;a href="https://bun.sh/" rel="noopener noreferrer"&gt;Bun&lt;/a&gt; is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; runtime built to serve the modern JS ecosystem. Aside from being a JavaScript runtime, Bun is a bundler, test runner, and NodeJS-compatible package manager.&lt;/p&gt;

&lt;p&gt;While &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;NodeJS&lt;/a&gt; remains a stable and popular choice as a runtime for JavaScript and &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; apps, Bun prioritizes speed and developer experience.&lt;/p&gt;

&lt;p&gt;Without further delay, let's jump in and install Bun so that we can explore more of what it has to offer.&lt;/p&gt;

&lt;p&gt;I’ll be using the &lt;a href="https://ubuntu.com/" rel="noopener noreferrer"&gt;Ubuntu&lt;/a&gt; 22.04 server from &lt;a href="https://www.hetzner.com/" rel="noopener noreferrer"&gt;Hetzner&lt;/a&gt; throughout this blog. If you’re on a different platform please visit Bun’s installation &lt;a href="https://bun.sh/docs/installation" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To install Bun run the following command on your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -fsSL https://bun.sh/install | bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevwkfsqtta8047jvgcf7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fevwkfsqtta8047jvgcf7.png" alt="Bun Installation" width="800" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the screenshot, I successfully installed Bun. And the download path is in &lt;code&gt;~/.bun/bin/bun&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since Bun is installed as a root user, other system users may be unable to use Bun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvibw8ninfad258fepxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvibw8ninfad258fepxz.png" alt="Bun Download Path" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the screenshot above, I was able to run the bun –version command while the root user was running the command. As soon as I switched the user to cleavr, which is a non-root user, I was unable to run the same command.&lt;/p&gt;

&lt;p&gt;To resolve this issue, you can copy the Bun installation to the &lt;code&gt;/usr/local/bin/&lt;/code&gt; directory. The &lt;code&gt;/usr&lt;/code&gt; directory stores read-only files that can be shared among system users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cp /root/.bun/bin/bun /usr/local/bin/bun&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7mh0o6kwa9ev58djazjc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7mh0o6kwa9ev58djazjc.png" alt="Bun System Wide Use" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you’ve successfully installed Bun, you can start building your projects using Bun. To scaffold an empty project, run the bun init command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwgmlhw4nikmn9r9gv9ix.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwgmlhw4nikmn9r9gv9ix.png" alt="Bun Scaffold Project" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;bun init&lt;/code&gt; command asks you to provide answers to a few prompts, you can provide the input or just press enter to accept the default answer for each prompt.&lt;/p&gt;

&lt;p&gt;It creates the required files to scaffold a minimal Bun project such as &lt;code&gt;package.json&lt;/code&gt;, &lt;code&gt;index.ts file&lt;/code&gt;, etc. &lt;br&gt;
At the end it also runs bun install to install the required dependencies.&lt;/p&gt;

&lt;p&gt;You can now run &lt;code&gt;bun run index.ts&lt;/code&gt; to execute a source file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43ekbjhejtim72byjdgc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43ekbjhejtim72byjdgc.png" alt="Bun Run Project" width="800" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we’ve installed the Bun runtime, scaffolded, and ran a new project using Bun runtime. I hope this blog helps you with setting up and running your projects using Bun.&lt;/p&gt;

&lt;p&gt;In the next part of this blog, we’ll set up a &lt;a href="https://nuxt.com/" rel="noopener noreferrer"&gt;Nuxt&lt;/a&gt; application with Bun.&lt;/p&gt;

&lt;p&gt;This content was originally posted on &lt;a href="https://cleavr.io/cleavr-slice/bun-runtime-introduction" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bunjs</category>
      <category>javascript</category>
      <category>cleavr</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Install MariaDB 10.4 on an Ubuntu 22.04 server</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Thu, 13 Apr 2023 09:21:54 +0000</pubDate>
      <link>https://dev.to/anishghimire862/install-mariadb-104-on-an-ubuntu-2204-server-4bnk</link>
      <guid>https://dev.to/anishghimire862/install-mariadb-104-on-an-ubuntu-2204-server-4bnk</guid>
      <description>&lt;p&gt;In this blog, we’ll show you how to install &lt;a href="https://mariadb.org/download/?t=mariadb&amp;amp;p=mariadb&amp;amp;r=10.4.28" rel="noopener noreferrer"&gt;MariaDB 10.4&lt;/a&gt; on &lt;a href="https://releases.ubuntu.com/jammy/" rel="noopener noreferrer"&gt;Ubuntu 22.04&lt;/a&gt; servers.&lt;/p&gt;

&lt;p&gt;We ran into some issues with MariaDB 10.4 installations on Ubuntu 22.04 servers. The MariaDB team stopped producing the deb package of MariaDB 10.04 for Ubuntu 22.04 servers. In Cleavr, we always want our users to have a better experience, so we planned to implement an alternate installation to either downgrade the versions of some security-related packages or a straightforward installation which takes almost 25-30 minutes 😬.&lt;/p&gt;

&lt;p&gt;However, We didn’t want to compromise installations nor to take so much of users time. So we decided not to support MariaDB 10.4 moving forward.&lt;/p&gt;

&lt;p&gt;However, if you still need to install MariaDB 10.4 on your Ubuntu 22.04 server, we’ll show you how you can do this using &lt;a href="https://mariadb.com/kb/en/installing-mariadb-binary-tarballs/" rel="noopener noreferrer"&gt;MariaDB Binary Tarballs&lt;/a&gt;. If you want to download any other unsupported versions of MariaDB, you can still follow this blog.&lt;/p&gt;

&lt;p&gt;Here’s a summary of what we will be doing throughout this blog:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SSH into the server&lt;/li&gt;
&lt;li&gt;Create system user and group&lt;/li&gt;
&lt;li&gt;Download MariaDB binary tarballs&lt;/li&gt;
&lt;li&gt;Extract the archive&lt;/li&gt;
&lt;li&gt;Create a symlink to point to MySQL&lt;/li&gt;
&lt;li&gt;Initialize the MariaDB data directory&lt;/li&gt;
&lt;li&gt;Fix ownership&lt;/li&gt;
&lt;li&gt;Export path to include mysql binary&lt;/li&gt;
&lt;li&gt;Configure MariaDB server&lt;/li&gt;
&lt;li&gt;Configure data directory&lt;/li&gt;
&lt;li&gt;Start MariaDB service&lt;/li&gt;
&lt;li&gt;Check MariaDB status&lt;/li&gt;
&lt;li&gt;Enable MariaDB service&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SSH into the server
&lt;/h2&gt;

&lt;p&gt;As a first step, &lt;a href="https://docs.cleavr.io/guides/ssh-server/" rel="noopener noreferrer"&gt;SSH&lt;/a&gt; into the server as a root user and add create a mysql user so that we can install MariaDB under the user and group mysql.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create system user and group
&lt;/h2&gt;

&lt;p&gt;Run the following command to create a new group and user called &lt;code&gt;mysql&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;groupadd mysql
useradd -g mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgsv1cwsugwskz01sbmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgsv1cwsugwskz01sbmk.png" alt="MySQL Add User" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Download MariaDB binary tarballs
&lt;/h2&gt;

&lt;p&gt;Now, we'll change our directory to /usr/local with cd /usr/local. This is the default directory where MariaDB is installed. So we’ll be downloading the binary tarballs in this directory. To download the tar file run the following wget command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://mirrors.aliyun.com/mariadb//mariadb-10.4.28/bintar-linux-systemd-x86_64/mariadb-10.4.28-linux-systemd-x86_64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re following this blog and intending to download 10.3, or any other versions, just replace the version number and run the command.&lt;/p&gt;

&lt;p&gt;For example, if you want to install MariaDB 10.3.38 the command will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://mirrors.aliyun.com/mariadb//mariadb-10.3.38/bintar-linux-systemd-x86_64/mariadb-10.4.28-linux-systemd-x86_64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk1dqmwrx11ift205sx6t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk1dqmwrx11ift205sx6t.png" alt="Download MariaDB Tarball" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The download may take around 25-30 minutes to complete depending on your internet connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extract the archive
&lt;/h2&gt;

&lt;p&gt;Once the file is downloaded, extract the files using the &lt;code&gt;tar&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tar -zxvpf mariadb-10.4.28-linux-systemd-x86_64.tar.gz&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Let's rename the extracted file to mariadb10.4 for convenience.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mv mariadb-10.4.28-linux-systemd-x86_64 mariadb10.4&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a symlink to point to MySQL
&lt;/h2&gt;

&lt;p&gt;Now let's create a symlink of the &lt;code&gt;mariadb10.4&lt;/code&gt; and point to &lt;code&gt;mysql&lt;/code&gt;. &lt;code&gt;/usr/local/mysql&lt;/code&gt; is the default location for MariaDB though it may be different in some platforms. Creating the symlink will also help you if you decide to change the MariaDB version.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ln -s /usr/local/mariadb10.4 mysql&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize the MariaDB data directory
&lt;/h2&gt;

&lt;p&gt;We need to initialize the MariaDB data directory and create the system tables. Run the following command to change the directory to &lt;code&gt;mysql&lt;/code&gt;, initialize the MariaDB data directory, and create the system tables:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd mysql &amp;amp;&amp;amp; ./scripts/mysql_install_db --user=mysql&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8pe4ea5ck42r9o18ijh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8pe4ea5ck42r9o18ijh.png" alt="Initialize MariaDB Data Directory" width="800" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix ownership
&lt;/h2&gt;

&lt;p&gt;We need to fix the ownership of our new files. Run the following chown commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chown -R root .
chown -R mysql data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Export path to include mysql binary
&lt;/h2&gt;

&lt;p&gt;We’ll now export the path where mysql exists by updating the &lt;code&gt;.bashrc&lt;/code&gt; file. We’ll then be able to test the connection by invoking clients such as &lt;code&gt;mysql&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run the following command to add the export path to &lt;code&gt;.bashrc&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "export PATH=$PATH:/usr/local/mysql/bin/" &amp;gt;&amp;gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;source ~/.bashrc&lt;/code&gt; so that you don’t have to restart your shell to reflect the new changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure MariaDB server
&lt;/h2&gt;

&lt;p&gt;You can configure mysqld (the MariaDB server) by copying the &lt;code&gt;mysql.server&lt;/code&gt; file to the right place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp support-files/mysql.server /etc/init.d/mysql.server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to copy the &lt;code&gt;mariadb.service&lt;/code&gt; file to its proper place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp support-files/systemd/mariadb.service /usr/lib/systemd/system/mariadb.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure data directory
&lt;/h2&gt;

&lt;p&gt;By default the &lt;code&gt;/usr/&lt;/code&gt; directory is write protected by systemd, so let's make our data directory writable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir /etc/systemd/system/mariadb.service.d/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat &amp;gt; /etc/systemd/system/mariadb.service.d/datadir.conf &amp;lt;&amp;lt;EOF
[Service]
ReadWritePaths=/usr/local/mysql/data
EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you run the above command reload the systemd manager configuration by running &lt;code&gt;systemctl daemon-reload&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start MariaDB service
&lt;/h2&gt;

&lt;p&gt;Finally, we can start the MariaDB service using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl start mariadb.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check MariaDB status
&lt;/h2&gt;

&lt;p&gt;Let's verify our installation by checking the status of MariaDB by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl status mariadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flwunejrh8i9xik46atjm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flwunejrh8i9xik46atjm.png" alt="MariaDB Status" width="800" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable MariaDB service
&lt;/h2&gt;

&lt;p&gt;If you want MariaDB to start automatically when you boot up your device enable the service by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl enable mariadb.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s all for this blog. I hope it helps you with MariaDB 10.4 installation on your Ubuntu 22.04 server.&lt;/p&gt;

&lt;p&gt;This blog was originally posted on &lt;a href="https://cleavr.io/cleavr-slice/install-mariadb104-on-ubuntu22" rel="noopener noreferrer"&gt;Cleavr Slice&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mariadb</category>
      <category>ubuntu</category>
      <category>cleavr</category>
    </item>
    <item>
      <title>TWO-FACTOR AUTHENTICATION (2FA) IMPLEMENTATION IN ADONISJS</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Thu, 01 Dec 2022 10:00:59 +0000</pubDate>
      <link>https://dev.to/anishghimire862/two-factor-authentication-2fa-implementation-in-adonisjs-4m8m</link>
      <guid>https://dev.to/anishghimire862/two-factor-authentication-2fa-implementation-in-adonisjs-4m8m</guid>
      <description>&lt;p&gt;In this blog, we’ll be discussing Two-Factor Authentication (2FA), and show you how we implemented 2FA in &lt;a href="https://cleavr.io/" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt; using a demo project with the &lt;a href="https://adonisjs.com/" rel="noopener noreferrer"&gt;AdonisJS&lt;/a&gt; web framework.&lt;/p&gt;

&lt;p&gt;Two-factor Authentication adds an extra layer of security to your online accounts by requiring an additional login credential in addition to a username and password. Instead of immediately gaining access after entering a username and password, users will be required to provide another piece of information, such as a PIN that’s sent through SMS or by using tokens retrieved from 2FA applications such as Google Authenticator.&lt;/p&gt;

&lt;p&gt;As a demonstration, I’ve created a demo application in which you can enable 2FA for an account. You can view the complete source code of the application &lt;a href="https://github.com/anishghimire862/adonisjs-2fa" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following are the list of activities that we’ll be doing throughout the blog:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Migrating the Database&lt;/li&gt;
&lt;li&gt;Updating Model&lt;/li&gt;
&lt;li&gt;Creating a User Controller to enable 2FA&lt;/li&gt;
&lt;li&gt;Creating an Auth Provider class&lt;/li&gt;
&lt;li&gt;Generating the QR Code&lt;/li&gt;
&lt;li&gt;Setting up an account on 2FA Applications&lt;/li&gt;
&lt;li&gt;Two Factor Challenge&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Migrating the Database
&lt;/h2&gt;

&lt;p&gt;First, we need to store the secret and recovery codes of a user enabling 2FA. We’ll create a &lt;a href="https://docs.adonisjs.com/guides/database/migrations" rel="noopener noreferrer"&gt;database migration&lt;/a&gt; to add two_factor_secret and two_factor_recovery_codes properties to the users table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table.text("two_factor_secret").nullable();
table.text("two_factor_recovery_codes").nullable();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Updating Model
&lt;/h2&gt;

&lt;p&gt;We don’t want to store these credentials in plain text on our database and don’t want to &lt;a href="https://docs.adonisjs.com/guides/models/serializing-models" rel="noopener noreferrer"&gt;serialize&lt;/a&gt; the model properties. Update the User model with the following block of the code. Models are located under app/Models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@column({
   serializeAs: null,
   consume: (value: string) =&amp;gt; (value ? JSON.parse(Encryption.decrypt(value) ?? '{}') : null),
   prepare: (value: string) =&amp;gt; Encryption.encrypt(JSON.stringify(value)),
 })
 public twoFactorSecret?: string

 @column({
   serializeAs: null,
   consume: (value: string) =&amp;gt; (value ? JSON.parse(Encryption.decrypt(value) ?? '[]') : []),
   prepare: (value: string[]) =&amp;gt; Encryption.encrypt(JSON.stringify(value)),
 })
 public twoFactorRecoveryCodes?: string[]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;serializeAs&lt;/code&gt;: null removes the model properties from the serialized output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.adonisjs.com/guides/security/encryption" rel="noopener noreferrer"&gt;Encryption&lt;/a&gt; is a module provided by AdonisJS which helps with the encryption and decryption of previously encrypted values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a User Controller to enable 2FA
&lt;/h2&gt;

&lt;p&gt;Now, let’s create a &lt;a href="https://docs.adonisjs.com/guides/controllers" rel="noopener noreferrer"&gt;controller&lt;/a&gt; that handles enabling two-factor authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default class UserController {
  public async enableTwoFactorAuthentication({ auth, view }) {
  const user = auth?.user

  user.twoFactorSecret = TwoFactorAuthProvider.generateSecret(user)
  user.twoFactorRecoveryCodes = await TwoFactorAuthProvider.generateRecoveryCodes()
  await user.save()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are generating secret and recovery codes for the user that’s enabling 2FA and storing them to our database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating an Auth Provider class
&lt;/h2&gt;

&lt;p&gt;I’ve created a class TwoFactorAuthProvider where the logic related to 2FA is located. Lets see how the generateSecret and generateRecoveryCode methods look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoFactor = require(‘node-2fa’)
import cryptoRandomString from 'crypto-random-string'

class TwoFactorAuthProvider {
  private issuer = Config.get('twoFactorAuthConfig.app.name') || 'adonisjs-2fa'

  public generateSecret(user: User) { const secret = twoFactor.generateSecret({ name: this.issuer, account: user.email })
  return secret.secret }

  public async generateRecoveryCodes() {
    const recoveryCodeLimit: number = 8
    const codes: string[] = []
    for (let i = 0; i &amp;lt; recoveryCodeLimit; i++) {
      const recoveryCode: string = `${await this.secureRandomString()}-${await this.secureRandomString()}`
      codes.push(recoveryCode)
    }
    return codes
  }

  public async secureRandomString() {
   return cryptoRandomString.async({ length: 10, type: 'hex' })
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create the secret, we’re using the generateSecret method provided by &lt;a href="https://github.com/jeremyscalpello/node-2fa" rel="noopener noreferrer"&gt;node-2fa&lt;/a&gt; package. You can install the package for your project by running the npm command npm install node-2fa --save.&lt;/p&gt;

&lt;p&gt;generateSecret will generate a user-specific 32-character secret. We’re providing the name of the app and the user’s email as parameters for the function. This secret key will be used to verify whether the token provided by the user during authentication is valid or not.&lt;/p&gt;

&lt;p&gt;We also generated recovery codes which can be used in case we’re unable to retrieve tokens from 2FA applications. We assign the user a list of recovery codes and each code can be used only once during the authentication process. The recovery codes are random strings generated using the &lt;a href="https://github.com/sindresorhus/crypto-random-string" rel="noopener noreferrer"&gt;cryptoRandomString&lt;/a&gt; library which can be installed using npm install crypto-random-string --save.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating the QR Code
&lt;/h2&gt;

&lt;p&gt;Once we generate the secret and recovery codes, we should provide users with a way to add the account to an authenticator application such as Google Authenticator. To easily set up an account with such authenticator applications, we’ll be providing them with a QR code. Authenticator applications generate a time-based one-time token, which is provided to the app or site during the login process when you’ve enabled 2FA for your account.&lt;/p&gt;

&lt;p&gt;We’ll be using &lt;a href="https://github.com/soldair/node-qrcode" rel="noopener noreferrer"&gt;qrcode&lt;/a&gt; NPM package for generating a QR Code. It can be installed using npm i --save-dev @types/qrcode for TypeScript projects or npm install qrcode --save.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoFactor = require(‘node-2fa’)

class TwoFactorAuthProvider {
  // ...
  public async generateQrCode(user: User) {
    const appName = encodeURIComponent(this.issuer)
    const userName = encodeURIComponent(user.email)
    const query = `?secret=${user.twoFactorSecret}&amp;amp;issuer=${appName}`
    const url = `otpauth://totp/${appName}${userName}${query}`
    const svg = await QRCode.toDataURL(url)
    return { svg, url }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that the issuer, email and secret are valid and match the values you’ve used while generating the secret. If they don’t match you may see a Key not recognized error while scanning the QR code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up an account on 2FA Applications
&lt;/h2&gt;

&lt;p&gt;We need to return the QR code from our UserController’s enableTwoFactorAuthentication method so the frontend can show the QR to the user for setting up the account on 2FA applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default class UserController {
  public async enableTwoFactorAuthentication({ auth, view }) {
    // …
    return view.render('pages/settings', {
      status: {
      type: 'success',
      message: 'Two factor authentication enabled.',
    },
    twoFactorEnabled: user.isTwoFactorEnabled,
    code: await TwoFactorAuthProvider.generateQrCode(user)
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the UI, you can show the QR code using the HTML image tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;img src="{{ code.svg }}" /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, you can also send the recovery codes with the same response and show the codes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two Factor Challenge
&lt;/h2&gt;

&lt;p&gt;Now the most important part of 2FA begins. We need to ask for a one-time token with the users that have 2FA enabled when they log in.&lt;/p&gt;

&lt;p&gt;First, we’ll verify whether the credentials supplied by users are valid or not. If the credentials are valid, we proceed to check whether 2FA is enabled or not. In the case where 2FA is enabled, we redirect users to the Two Factor Challenge page where they’ll be asked to provide a one-time token or a recovery code. In other cases, we log in the users directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default class AuthController {
  public async login({ request, response, auth, view, session }) {
    const { email, password } = request.only(["email", "password"]);
    const user = await auth.use("web").verifyCredentials(email, password);

    if (user.isTwoFactorEnabled) {
      session.put("login.id", user.id);
      return view.render("pages/two-factor-challenge");
    }

    session.forget("login.id");
    session.regenerate();
    await auth.login(user);
    response.redirect("/");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’re storing the user ID in the session before redirecting the user to the two-factor challenge page so that we’re aware of the user who is trying to authenticate.&lt;/p&gt;

&lt;p&gt;Once the user is on the two-factor challenge page, the user will be asked to enter either a token or a recovery code. Then, once the submit button is clicked we need to verify that either the token or recovery code is valid for the user or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default class AuthController {
  // …
  public async twoFactorChallenge({ request, session, view, auth, response }) {
    const { code, recoveryCode } = request.only(["code", "recoveryCode"]);
    const user = await User.query()
      .where("id", session.get("login.id"))
      .first();

    session.forget("login.id");
    session.regenerate();

    if (code) {
      const isValid = await twoFactor.verifyToken(user.twoFactorSecret, code);
      if (isValid) {
        await auth.login(user);
        return response.redirect("/");
      }
    } else if (recoveryCode) {
      const codes = user?.twoFactorRecoveryCodes ?? [];
      if (codes.includes(recoveryCode)) {
        user.twoFactorRecoveryCodes = codes.filter(c =&amp;gt; c !== recoveryCode);
        await user.save();
        await auth.login(user);
        return response.redirect("/");
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What goes here is, we receive the 2FA code provided by the user and find the user using the user ID stored in the session. We’ll be using the verifyToken method provided by node-2fa. It then checks if a time-based token matches a token from the secret key. In the case of recovery codes, we check whether the recovery code provided by the user exists in our system for the user or not, and then remove the recovery code once it has been used. Don’t forget to clear the session variables once the login process completes.&lt;/p&gt;

&lt;p&gt;That’s it! Your users can now enable 2FA for their accounts and enjoy the additional security it provides. The code used in this blog is available over on &lt;a href="https://github.com/anishghimire862/adonisjs-2fa" rel="noopener noreferrer"&gt;here&lt;/a&gt;. I hope you found this blog useful.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
    </item>
    <item>
      <title>How to setup a Tunneling server using Cleavr</title>
      <dc:creator>Anish Ghimire</dc:creator>
      <pubDate>Thu, 24 Mar 2022 06:13:08 +0000</pubDate>
      <link>https://dev.to/anishghimire862/how-to-setup-a-tunneling-server-using-cleavr-5b2h</link>
      <guid>https://dev.to/anishghimire862/how-to-setup-a-tunneling-server-using-cleavr-5b2h</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g1mzlak8j00y208glzt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g1mzlak8j00y208glzt.png" alt="How to setup a Tunneling server using Cleavr" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On &lt;a href="https://cleavr.io/" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt;, the majority of activities take place on the user's servers. For many of these activities, such as server provisioning and deployments, we show the status real-time status on the Cleavr UI.&lt;/p&gt;

&lt;p&gt;But, how do we communicate the activities that are taking place on the user's server?&lt;/p&gt;

&lt;p&gt;If it's in production, we can send status updates between servers, which is a relatively straightforward process.&lt;/p&gt;

&lt;p&gt;However, for local development, we use a tunneling server to expose our local application to the internet.&lt;/p&gt;

&lt;p&gt;There are plenty of tunneling solutions that can be used for local development, such as: &lt;a href="https://ngrok.com/" rel="noopener noreferrer"&gt;Ngrok&lt;/a&gt;, &lt;a href="http://localtunnel.github.io/www/" rel="noopener noreferrer"&gt;Localtunnel&lt;/a&gt;, and &lt;a href="https://expose.dev/" rel="noopener noreferrer"&gt;Expose&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But, these solutions will impose certain restrictions at some level.&lt;/p&gt;

&lt;p&gt;Today, we’re going to discuss how we can create our own tunneling server using &lt;a href="https://cleavr.io/" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt;. During the writing of this blog, I found &lt;a href="https://igauravsehrawat.com/build-your-own-ngrok-4-easy-steps/" rel="noopener noreferrer"&gt;an article&lt;/a&gt; that was helpful to me and that I used as a reference.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The good news about owning your own tunneling server is that you won’t have to worry about some headaches such as frequently changing sub-domains,having a random subdomain being assigned, or experiencing frequent disconnections.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To begin setting up our own tunneling server, we'll first provision a new server with the bare minimum specs so that we won’t have to spend a lot of money on this solution.&lt;/p&gt;

&lt;p&gt;You can also make use of Cleavr’s free domain instead of purchasing a custom one for some added savings.&lt;/p&gt;

&lt;p&gt;Now, it’s time to create a site in which we’ll expose our local site/app on the internet.&lt;/p&gt;

&lt;p&gt;Head over to your newly provisioned server and click on &lt;code&gt;Add Site&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmzcscz9levm5ronq2b6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmzcscz9levm5ronq2b6.png" alt="Create Generic Port Website on Cleavr" width="800" height="1093"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the App Type, select Generic Port App.&lt;/p&gt;

&lt;p&gt;Provide your domain name, desired port number and user as well. If you’re using a custom domain, we encourage you to enable free SSL.&lt;/p&gt;

&lt;p&gt;Once you’ve created your site, you can now go to the newly created site and navigate to the Site NGINX Config page. On this page, update the config required for our tunneling site to work. You can simply update the NGINX config with the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map $http_upgrade $connection_upgrade {
   default upgrade;
   ''      close;
}

server {
   server_name example.cleavr-one.com;
   include cleavr-conf/example.cleavr-one.com/*.conf;

   location / {
       proxy_pass http://localhost:PORT;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_set_header X-NginX-Proxy true;

       # Enables WS support
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection $connection_upgrade;
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be sure to update &lt;code&gt;example.cleavr-one.com&lt;/code&gt; with your domain name and &lt;code&gt;PORT&lt;/code&gt; with the port number you’ve used during site creation.&lt;/p&gt;

&lt;p&gt;Now, click the &lt;code&gt;update&lt;/code&gt; button and you will be done with the configuration part and the most boring part for some of you 😉.&lt;/p&gt;

&lt;p&gt;We’re almost done, but if we stop right here you’ll have to enter your server password every time you want to expose your local server to the internet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleavr.io/" rel="noopener noreferrer"&gt;Cleavr&lt;/a&gt; provides a way to add your &lt;a href="https://docs.cleavr.io/ssh-keys/" rel="noopener noreferrer"&gt;SSH keys&lt;/a&gt; to the Server directly from the UI. You just need to go to Server &amp;gt; SSH Keys and add your SSH key to the server.&lt;/p&gt;

&lt;p&gt;We’re all done now. Lets expose our local server to the internet with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -N -R SITE_PORT:localhost:LOCAL_PORT serverUser@serverIP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BOOM!!! Now you can open your site example.cleavr-one.com in a browser, and you’ll see your local app being loaded there.&lt;/p&gt;

</description>
      <category>tunneling</category>
      <category>cleavr</category>
      <category>ngrok</category>
      <category>localtunnel</category>
    </item>
  </channel>
</rss>
