<?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: Divine Orji</title>
    <description>The latest articles on DEV Community by Divine Orji (@dpkreativ).</description>
    <link>https://dev.to/dpkreativ</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%2F166395%2Fdbfebdb9-0bc1-4cb9-92f6-1ece8f8e5a7e.jpg</url>
      <title>DEV Community: Divine Orji</title>
      <link>https://dev.to/dpkreativ</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dpkreativ"/>
    <language>en</language>
    <item>
      <title>How to access Neon Postgres from AWS Lambda functions via serverless driver</title>
      <dc:creator>Divine Orji</dc:creator>
      <pubDate>Thu, 29 Feb 2024 20:48:16 +0000</pubDate>
      <link>https://dev.to/hackmamba/how-to-access-neon-postgres-from-aws-lambda-functions-via-serverless-driver-3ad4</link>
      <guid>https://dev.to/hackmamba/how-to-access-neon-postgres-from-aws-lambda-functions-via-serverless-driver-3ad4</guid>
      <description>&lt;p&gt;Serverless is a computing paradigm that provides a pay-as-you-use model. It lets you deploy your projects easily and scale to meet large demands without the stress of maintaining or managing servers. &lt;/p&gt;

&lt;p&gt;Wherever there are conversations on serverless, two important concepts often come up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compute — the processing power of a server.&lt;/li&gt;
&lt;li&gt;Storage — the capacity to store data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditionally, accessing a database from a serverless computing service like &lt;a href="https://aws.amazon.com/lambda/?utm_source=hackmamba&amp;amp;utm_medium=blog&amp;amp;utm_id=HMBcommunity" rel="noopener noreferrer"&gt;AWS Lambda&lt;/a&gt; is tricky due to the differences in connection protocols. Lambda functions are “ephemeral” — relying on short-lived, HTTP-centric connections, while databases utilize long-lived, TCP-centric connections.&lt;/p&gt;

&lt;p&gt;It is possible to send a single-shot HTTP query to retrieve data from your database. However, maintaining a persistent connection (like streaming data to your clients) could lead to timeouts in your lambda runtime or compute costs that balloon unexpectedly.&lt;/p&gt;

&lt;p&gt;One way to solve this problem is connecting via a gateway or proxy. This way, your client can establish a long-lived connection (using WebSockets) with the proxy, which then interacts with your backend using standard HTTP requests.&lt;/p&gt;

&lt;p&gt;Neon’s &lt;a href="https://neon.tech/docs/serverless/serverless-driver?ref=hm" rel="noopener noreferrer"&gt;serverless driver&lt;/a&gt; is a drop-in replacement for &lt;code&gt;node-postgres&lt;/code&gt; that combines the benefits of WebSockets and HTTP into one simple package, &lt;a href="https://neon.tech/blog/quicker-serverless-postgres?ref=hm" rel="noopener noreferrer"&gt;optimiz&lt;/a&gt;&lt;a href="https://neon.tech/blog/quicker-serverless-postgres?ref=hm" rel="noopener noreferrer"&gt;ing&lt;/a&gt; &lt;a href="https://neon.tech/blog/quicker-serverless-postgres?ref=hm" rel="noopener noreferrer"&gt;the number of round trips&lt;/a&gt; required to interact with a Neon Postgres database.&lt;/p&gt;

&lt;p&gt;This article will teach you how to access a Neon Postgres database from an AWS Lambda function via Neon’s serverless driver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684186287_Untitled.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684186287_Untitled.png" alt="Data flow between Neon and AWS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Source code&lt;/strong&gt;&lt;br&gt;
Here’s a link to the GitHub &lt;a href="https://github.com/dpkreativ/neon-serverless-lambda?utm_source=hackmamba&amp;amp;utm_medium=blog&amp;amp;utm_id=HMBcommunity" rel="noopener noreferrer"&gt;repository&lt;/a&gt; for this article’s demo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A Neon account. Neon offers a generous free tier that you can start with. Get it &lt;a href="https://console.neon.tech/sign_in" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;An AWS account. Explore its free tier &lt;a href="https://aws.amazon.com/free" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; installed on your PC. It comes with &lt;code&gt;npm&lt;/code&gt;, which you will use to add Neon’s serverless driver to your project.&lt;/li&gt;
&lt;li&gt;A code editor. This article’s demo was built with &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up a Neon database
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create a project
&lt;/h3&gt;

&lt;p&gt;When you &lt;a href="https://console.neon.tech/sign_in" rel="noopener noreferrer"&gt;sign up on Neon&lt;/a&gt;, you’ll be prompted to create a project and a database like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684328889_Untitled%2B1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684328889_Untitled%2B1.png" alt="Create Project page showing inputs for Project name, Database name, and Region"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once created, your project’s dashboard will contain a general overview of your database connection details, branches, compute, and storage data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684392578_Untitled%2B2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701684392578_Untitled%2B2.png" alt="Neon dashboard showing Connection Details, Branches, Usage, and Storage details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please take note of your database connection string because you will add it as an environment variable in your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seed data
&lt;/h3&gt;

&lt;p&gt;In your Neon project’s console sidebar, click on ‘&lt;strong&gt;SQL Editor&lt;/strong&gt;’ and run the queries below to seed your database with some data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;    &lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;cars&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;NOW&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;cars&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;VALUES&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Toyota'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Camry'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Honda'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Civic'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Ford'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Mustang'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Tesla'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Model S'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Chevrolet'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Silverado'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'BMW'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'3 Series'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Mercedes-Benz'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'E-Class'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Jeep'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Wrangler'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Audi'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Q5'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Subaru'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Outback'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This SQL script creates a &lt;code&gt;cars&lt;/code&gt; table with columns for &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;car&lt;/code&gt;, &lt;code&gt;model&lt;/code&gt;, and &lt;code&gt;created_at&lt;/code&gt;, then inserts the provided car makes and models into the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694107965_seed-database.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694107965_seed-database.gif" alt="GIF demonstrating how to run an SQL script in Neon’s SQL editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing Neon’s database with serverless driver
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Setup project
&lt;/h3&gt;

&lt;p&gt;In your terminal, navigate to your project’s folder and start a new Node.js project by running the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;mkdir &lt;/span&gt;neon-serverless-lambda
    &lt;span class="nb"&gt;cd &lt;/span&gt;neon-serverless-lambda
    npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a Node.js project with default values. Open your project in a code editor and update the &lt;code&gt;package.json&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"neon-serverless-lambda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="err"&gt;Error:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;no&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;test&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;specified\\&lt;/span&gt;&lt;span class="s2"&gt;" &amp;amp;&amp;amp; exit 1"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"keywords"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you added &lt;code&gt;"type": "module"&lt;/code&gt; to enable EcmaScript’s &lt;code&gt;import/export&lt;/code&gt; functionality.&lt;br&gt;
In your project’s terminal, run the command below to install Neon’s serverless driver:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    npm &lt;span class="nb"&gt;install&lt;/span&gt; @neondatabase/serverless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Write function
&lt;/h3&gt;

&lt;p&gt;Open your project in a code editor, then create an &lt;code&gt;index.js&lt;/code&gt; file and update it with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="c1"&gt;// index.js (using `neon` object)&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;neon&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@neondatabase/serverless&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;neon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SELECT * from cars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Successful&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;}),&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imported the &lt;code&gt;neon&lt;/code&gt; object from &lt;code&gt;@neondatabase/serverless&lt;/code&gt;. This object will allow you to connect to and run SQL queries on a Neon database using a connection string.&lt;/li&gt;
&lt;li&gt;Created a &lt;code&gt;handler()&lt;/code&gt; function with an &lt;code&gt;event&lt;/code&gt; parameter.&lt;/li&gt;
&lt;li&gt;In your &lt;code&gt;handler()&lt;/code&gt; function, you wrote a &lt;code&gt;try-catch&lt;/code&gt; block that attempts to establish a connection to the database using the &lt;code&gt;neon&lt;/code&gt; object and the &lt;code&gt;DATABASE_URL&lt;/code&gt; environment variable. It executes a SQL query (&lt;code&gt;SELECT * from cars&lt;/code&gt;) to retrieve all rows from the "&lt;strong&gt;cars&lt;/strong&gt;" table. Any errors during the database operation are logged using &lt;code&gt;console.log()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;After fetching the rows from the database, your function constructs and returns an HTTP response with a status code of 200 (indicating success) and a JSON body containing a success message ('&lt;strong&gt;Successful&lt;/strong&gt;') along with the retrieved rows (&lt;code&gt;data: rows&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Choosing between the Neon serverless driver’s &lt;code&gt;neon&lt;/code&gt; or &lt;code&gt;Pool/Client&lt;/code&gt; objects&lt;/strong&gt; &lt;br&gt;
If you want to execute multiple queries in a single connection, Neon’s &lt;code&gt;Pool&lt;/code&gt; object uses WebSockets and can bring latencies down to 4ms once a connection is established. However, it is best to use the &lt;code&gt;neon&lt;/code&gt; object for single-shot queries. Check out &lt;a href="https://neon.tech/blog/http-vs-websockets-for-postgres-queries-at-the-edge?ref=hm" rel="noopener noreferrer"&gt;this&lt;/a&gt; &lt;a href="https://neon.tech/blog/http-vs-websockets-for-postgres-queries-at-the-edge?ref=hm" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://neon.tech/blog/http-vs-websockets-for-postgres-queries-at-the-edge?ref=hm" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; for more insights.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Prepare for deployment
&lt;/h3&gt;

&lt;p&gt;In your PC’s file explorer, navigate to your project’s folder and zip all of its contents:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701686467810_Untitled%2B3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701686467810_Untitled%2B3.png" alt="File explorer showing selected Neon code and .zip file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will upload this &lt;code&gt;.zip&lt;/code&gt; file to AWS while creating the Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying to AWS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create a Lambda function
&lt;/h3&gt;

&lt;p&gt;In your browser, log into your &lt;a href="https://console.aws.amazon.com/" rel="noopener noreferrer"&gt;AWS console&lt;/a&gt;, search for “&lt;strong&gt;Lambda&lt;/strong&gt;,” and select it from the results:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701686829591_Untitled%2B4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701686829591_Untitled%2B4.png" alt="AWS console with search results for Lambda"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click “&lt;strong&gt;Create function&lt;/strong&gt;” and fill out the basic information for your new Lambda function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694353994_Untitled%2B5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694353994_Untitled%2B5.png" alt="Create function page with inputs for your Lambda’s basic information"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After filling out the required basic information, scroll down and click “&lt;strong&gt;Create function&lt;/strong&gt;” to finish creating your new Lambda function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694551082_Untitled%2B6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694551082_Untitled%2B6.png" alt="neon-serverless-lambda dashboard on AWS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload your code as a zip file
&lt;/h3&gt;

&lt;p&gt;In your Lambda function’s dashboard, scroll down to “&lt;strong&gt;Code source&lt;/strong&gt;”, click “&lt;strong&gt;Upload from&lt;/strong&gt;”, and select “&lt;strong&gt;.zip file&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694632659_Untitled%2B7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694632659_Untitled%2B7.png" alt="Code source section in AWS Lambda"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to your project’s folder and select the .zip file you created in the last section, then click “&lt;strong&gt;Save&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694673000_Untitled%2B8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694673000_Untitled%2B8.png" alt="AWS Lambda dashboard with .zip file selected"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Set environment variables
&lt;/h3&gt;

&lt;p&gt;In your Lambda function’s dashboard, click “&lt;strong&gt;Configuration&lt;/strong&gt;”, then select “&lt;strong&gt;Environment variables&lt;/strong&gt;” and click the “&lt;strong&gt;Edit&lt;/strong&gt;” button:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694713697_Untitled%2B9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694713697_Untitled%2B9.png" alt="Environment variables screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the “&lt;strong&gt;Edit environment variables&lt;/strong&gt;” page, click “&lt;strong&gt;Add environment variable&lt;/strong&gt;”, then input &lt;code&gt;DATABASE_URL&lt;/code&gt; as the variable key and your Neon project’s database connection string as the value, then click “&lt;strong&gt;Save&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694751377_Untitled%2B10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694751377_Untitled%2B10.png" alt="Edit environment variables page with key and value inputs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test your deployment
&lt;/h3&gt;

&lt;p&gt;In your Lambda function, click “&lt;strong&gt;Test&lt;/strong&gt;” to create a new test event, then fill out the event name, and click “&lt;strong&gt;Save&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694808443_Untitled%2B11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694808443_Untitled%2B11.png" alt="Test event screen with inputs to create a reusable test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After saving your test, click the “&lt;strong&gt;Test&lt;/strong&gt;” button to run it. If it is successful, you will see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694839570_Untitled%2B12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694839570_Untitled%2B12.png" alt="Successful test result on AWS Lambda"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating and testing your API
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create an API with AWS API Gateway
&lt;/h3&gt;

&lt;p&gt;In your Lambda’s “&lt;strong&gt;Function overview&lt;/strong&gt;” section, click “&lt;strong&gt;Add trigger&lt;/strong&gt;” and select “&lt;strong&gt;API Gateway&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694906318_Untitled%2B13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694906318_Untitled%2B13.png" alt="Add trigger page with API Gateway selected"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select “&lt;strong&gt;Create a new API&lt;/strong&gt;”, specify “&lt;strong&gt;HTTP API&lt;/strong&gt;” as the API type and the security mechanism as “&lt;strong&gt;Open&lt;/strong&gt;”, then scroll down and click “&lt;strong&gt;Add&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694962406_Untitled%2B14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701694962406_Untitled%2B14.png" alt="API Gateway Trigger configuration options"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your API endpoint has been created, scroll down to “&lt;strong&gt;Triggers&lt;/strong&gt;” to see its URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701695500731_Untitled%2B15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701695500731_Untitled%2B15.png" alt="API Gateway trigger for neon-serverless-lambda showing its endpoint URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test your API endpoint
&lt;/h3&gt;

&lt;p&gt;To quickly test your new endpoint, copy its URL and make a “&lt;strong&gt;GET&lt;/strong&gt;” request in your preferred API testing platform:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701695548832_Untitled%2B16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_0B288B3ADBD6B4ACFE38D8459D9358ABFF511A58AC71D6877694EE2BA6485001_1701695548832_Untitled%2B16.png" alt="Thunderclient UI to test API endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Following this guide, you’ve had hands-on experience bridging the gap between AWS Lambda and Neon’s database using the Neon serverless driver. In this guide, you manually zipped and deployed your code; however, you can explore &lt;a href="https://www.serverless.com/?utm_source=hackmamba&amp;amp;utm_medium=blog&amp;amp;utm_id=HMBcommunity" rel="noopener noreferrer"&gt;The Serverless Framework&lt;/a&gt; or &lt;a href="https://docs.aws.amazon.com/serverless-application-model/?utm_source=hackmamba&amp;amp;utm_medium=blog&amp;amp;utm_id=HMBcommunity" rel="noopener noreferrer"&gt;AWS Serverless Application Model&lt;/a&gt; &lt;a href="http://?utm_source=hackmamba&amp;amp;utm_medium=blog&amp;amp;utm_id=HMBcommunity" rel="noopener noreferrer"&gt;(SAM)&lt;/a&gt; for continuous integration and deployment.&lt;/p&gt;

&lt;p&gt;Serverless computing can help you scale to meet enormous demands. When paired with a robust, scalable, serverless database service like Neon, the result is a seamless experience for your development team and end users. Neon also offers innovative features like database branching, autoscaling, and bottomless storage, saving you time and money. &lt;a href="https://neon.tech/?ref=hm" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; to explore its free tier today.&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>neon</category>
      <category>serverless</category>
      <category>aws</category>
    </item>
    <item>
      <title>Build a Real Time Leaderboard in Nuxt.js and Pink Design</title>
      <dc:creator>Divine Orji</dc:creator>
      <pubDate>Tue, 16 May 2023 10:27:06 +0000</pubDate>
      <link>https://dev.to/hackmamba/build-a-real-time-leaderboard-in-nuxtjs-and-pink-design-2k65</link>
      <guid>https://dev.to/hackmamba/build-a-real-time-leaderboard-in-nuxtjs-and-pink-design-2k65</guid>
      <description>&lt;p&gt;In modern software development, real-time updates are vital, especially for applications that rely on up-to-date information for users. In such scenarios, changes made to the app's database are immediately reflected in the user interface, eliminating the need for manual refreshing or waiting for server responses.&lt;/p&gt;

&lt;p&gt;Appwrite is a popular backend-as-a-service platform that simplifies database management, user authentication, account management, and storage. Its real-time functionality is especially vital for chat apps, analytics, live scoreboards, or more complex features like live streaming and collaborative editing.&lt;/p&gt;

&lt;p&gt;This blog post illustrates how to use Appwrite's real-time feature to create a racing leaderboard in Nuxt.js. You will style your leaderboard using Appwrite's &lt;a href="https://pink.appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Pink Design&lt;/a&gt; system, giving it a cohesive and visually appealing look.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;source code&lt;/strong&gt; for this project is available below:&lt;br&gt;
&lt;a href="https://github.com/dpkreativ/nuxt-racing-leaderboard" rel="noopener noreferrer"&gt;Real-Time Racing Leaderboard | GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Jump ahead:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Setting Up a Nuxt Project&lt;/li&gt;
&lt;li&gt;Setting Up an Appwrite Database&lt;/li&gt;
&lt;li&gt;Implementing Real Time Updates with Appwrite&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To create a real-time leaderboard in Nuxt.js, it is essential to meet the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a solid understanding of JavaScript, Vue.js, CSS, and styling.&lt;/li&gt;
&lt;li&gt;Verify that Node.js is installed on your personal computer (PC) by running &lt;code&gt;node -v&lt;/code&gt; in your terminal. If not, download and install it from the &lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;official website&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Verify that Yarn is installed on your PC by running &lt;code&gt;yarn -v&lt;/code&gt; in your terminal. If not, install it by running &lt;code&gt;npm install --location=global yarn&lt;/code&gt; in your terminal.&lt;/li&gt;
&lt;li&gt;Set up a remote Appwrite instance with &lt;a href="https://cloud.appwrite.io/login?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Appwrite Cloud&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;or&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify that Docker Desktop is installed on your PC by running &lt;code&gt;docker -v&lt;/code&gt; in your terminal, or follow &lt;a href="https://docs.docker.com/desktop/" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; to install it. Then set up a local Appwrite instance on your PC by following &lt;a href="https://dev.to/hackmamba/create-a-local-appwrite-instance-in-3-steps-19n9?utm_source=hackmamba&amp;amp;utm_medium=hackmamba"&gt;this blog post&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;You can also set up your remote instance on &lt;a href="https://docs.digitalocean.com/products/marketplace/catalog/appwrite/" rel="noopener noreferrer"&gt;Digital Ocean&lt;/a&gt; or &lt;a href="https://www.gitpod.io/guides/appwrite-and-gitpod" rel="noopener noreferrer"&gt;Gitpod&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Setting Up a Nuxt Project
&lt;/h2&gt;

&lt;p&gt;You can create a new Nuxt.js project by navigating to your preferred repo in your terminal and running the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nuxi init &amp;lt;project name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, to speed up the development process, bootstrap your project with &lt;a href="https://github.com/dpkreativ/racing-leaderboard-starter/generate" rel="noopener noreferrer"&gt;this starter template&lt;/a&gt; on GitHub. It comes with &lt;a href="https://nuxt.com/" rel="noopener noreferrer"&gt;Nuxt 3&lt;/a&gt;, Appwrite's &lt;a href="https://pink.appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Pink Design&lt;/a&gt;, and &lt;a href="https://nuxt.com/modules/appwrite" rel="noopener noreferrer"&gt;Appwrite's Nuxt module&lt;/a&gt;. It also contains some helper functions in the &lt;code&gt;utils&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913528643_Untitled-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913528643_Untitled-min.png" alt="Generate repository from starter repo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clone your generated repo to your preferred local directory, and run &lt;code&gt;yarn&lt;/code&gt; to install the dependencies listed in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you encounter any errors while installing dependencies, it is most likely because you need to add your Appwrite details—endpoint, project ID, database ID, and collection ID—to a &lt;code&gt;.env&lt;/code&gt; file. Don't worry about it for now. Set up your Appwrite Database first, then add the necessary details to your &lt;code&gt;.env&lt;/code&gt; file and rerun &lt;code&gt;yarn&lt;/code&gt; in your terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913560521_Untitled%2B1-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913560521_Untitled%2B1-min.png" alt="Install your dependencies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up an Appwrite Database
&lt;/h2&gt;

&lt;p&gt;If you have an Appwrite Cloud account, click &lt;a href="https://cloud.appwrite.io/login?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;here&lt;/a&gt; to open it in your browser and create a new project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913587492_Untitled%2B2-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913587492_Untitled%2B2-min.png" alt="Create project on Appwrite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your Appwrite project, click on &lt;strong&gt;Databases&lt;/strong&gt;, and then click on &lt;strong&gt;Create Database&lt;/strong&gt; to create a new database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913599996_Untitled%2B3-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913599996_Untitled%2B3-min.png" alt="Create database in Appwrite project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your newly created database, create a collection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913617318_Untitled%2B4-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913617318_Untitled%2B4-min.png" alt="Create a database collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Settings&lt;/strong&gt; tab of your new collection, scroll down to &lt;strong&gt;Update Permissions&lt;/strong&gt; and set &lt;strong&gt;Any&lt;/strong&gt; to &lt;strong&gt;Read&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913633951_Untitled%2B5-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913633951_Untitled%2B5-min.png" alt="Update read and write permissions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This ensures that anybody can view the data on your database. If you want your users to create, update, or delete documents in the database, check the necessary boxes.&lt;br&gt;
In your collection, click on the &lt;strong&gt;Attributes&lt;/strong&gt; tab and create some attributes for each document in your collection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913648706_Untitled%2B6-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913648706_Untitled%2B6-min.png" alt="Create attributes for your collection's documents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will create four attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;car&lt;/code&gt; - String&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;carNumber&lt;/code&gt; - Integer&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;driver&lt;/code&gt; - String&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;duration&lt;/code&gt; - Integer (in seconds)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913664874_Untitled%2B7-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913664874_Untitled%2B7-min.png" alt="Attributes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Seed the database with some data by clicking on the &lt;strong&gt;Documents&lt;/strong&gt; tab and clicking &lt;strong&gt;Create document&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913678114_Untitled%2B8-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913678114_Untitled%2B8-min.png" alt="Collection of Documents in Leaderboard database"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing Real Time Updates with Appwrite
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Setting up environment variables
&lt;/h3&gt;

&lt;p&gt;In your code editor, create a &lt;code&gt;.env&lt;/code&gt; in your project's root directory or rename &lt;code&gt;.env.example&lt;/code&gt; to &lt;code&gt;.env&lt;/code&gt;. It should contain the text below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APPWRITE_ENDPOINT=
APPWRITE_PROJECT_ID=
APPWRITE_DATABASE_ID=
APPWRITE_COLLECTION_ID=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow this guide to update your &lt;code&gt;.env&lt;/code&gt; file with the correct data from your Appwrite database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you created your database with Appwrite Cloud, your &lt;code&gt;APPWRITE_ENDPOINT&lt;/code&gt; is &lt;code&gt;https://cloud.appwrite.io/v1&lt;/code&gt;. If you're running a local instance, use &lt;code&gt;http://localhost/80&lt;/code&gt; as your endpoint. If you hosted on Digital Ocean or Gitpod, use the provided endpoint for your chosen platform.&lt;/li&gt;
&lt;li&gt;Store your project's ID in &lt;code&gt;APPWRITE_PROJECT_ID&lt;/code&gt;, your database ID in &lt;code&gt;APPWRITE_DATABASE_ID&lt;/code&gt;, and your collection ID in &lt;code&gt;APPWRITE_COLLECTION_ID&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In your project's root directory, update &lt;code&gt;nuxt.config.ts&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// https://nuxt.com/docs/api/configuration/nuxt-config&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineNuxtConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;runtimeConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;public&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APPWRITE_DATABASE_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APPWRITE_COLLECTION_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;nuxt-appwrite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APPWRITE_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APPWRITE_PROJECT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you set up Nuxt.js' runtime config to read the data from your &lt;code&gt;.env&lt;/code&gt; file and set up &lt;code&gt;nuxt-appwrite&lt;/code&gt; module with the correct endpoint and project ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Data From Appwrite's Database
&lt;/h3&gt;

&lt;p&gt;Open &lt;code&gt;app.vue&lt;/code&gt; and update the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
import '@appwrite.io/pink';
import '@appwrite.io/pink-icons';

const config = useRuntimeConfig();

const &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; = useAppwrite();

// Create an anonymous session if it doesn't already exist
if (account.getSession === null) &lt;span class="si"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAnonymousSession&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;

// Get initial data from the database
const &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;documents&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; = await database.listDocuments(
  config.database,
  config.collection
);

// Add racing data to state
const &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;racingData&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; = useState('racingData', () =&amp;gt; sortData(documents));
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up runtime config to access data from your &lt;code&gt;.env&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;Imported &lt;code&gt;account&lt;/code&gt;, &lt;code&gt;client&lt;/code&gt;, and &lt;code&gt;database&lt;/code&gt; from Appwrite's Nuxt.js module&lt;/li&gt;
&lt;li&gt;Created an anonymous Appwrite session so any user can access your database&lt;/li&gt;
&lt;li&gt;Got the initial data from your leaderboard database and destructured it to get the &lt;code&gt;documents&lt;/code&gt; key; this contains an array of all the documents in your database&lt;/li&gt;
&lt;li&gt;Sorted your array of documents by duration using a helper function (&lt;code&gt;sortData&lt;/code&gt;) and added the sorted array to Nuxt.js' state with &lt;code&gt;racingData&lt;/code&gt; as its variable name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still in your &lt;code&gt;app.vue&lt;/code&gt;, update &lt;code&gt;&amp;lt;RacingLeaderboard&amp;gt;&lt;/code&gt; in your &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;NuxtLayout&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;RacingLeaderboard&lt;/span&gt; &lt;span class="na"&gt;:data=&lt;/span&gt;&lt;span class="s"&gt;"racingData"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/NuxtLayout&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the project with &lt;code&gt;yarn dev&lt;/code&gt; and open &lt;code&gt;localhost:3000&lt;/code&gt; in your terminal, you will see the UI below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913698490_Untitled%2B9-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913698490_Untitled%2B9-min.png" alt="Racing leaderboard UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Subscribing to Real Time Updates
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;app.vue&lt;/code&gt; &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, add the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
// ...previous code, do not delete; just add the one below

// Subscribe to real-time updates from the database
onMounted(() =&amp;gt; &lt;span class="si"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`databases.&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.collections.&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.documents`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;updateState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;racingData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;);
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up &lt;code&gt;onMounted()&lt;/code&gt; to ensure that the &lt;code&gt;client.subscribe()&lt;/code&gt; method only works when the project is loaded on the browser; this is because it requires the &lt;code&gt;window&lt;/code&gt; method, which is only available on the browser&lt;/li&gt;
&lt;li&gt;Your &lt;code&gt;client.subscribe()&lt;/code&gt; method takes in the exact location of your documents as its channel and updates your state with a helper function when there are any changes to the documents in your database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a preview of how it will work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913709081_ezgif.com-optimize.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_6DE1294194673DC40A51BBD0CA09AD4B606B742A10609854076A6E417520F712_1679913709081_ezgif.com-optimize.gif" alt="Real-time updates in Appwrite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that you don't need to refresh the browser to see updates to your database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This blog post demonstrated Appwrite's real-time functionality in a racing leaderboard. The post covered how to set up a Nuxt.js project with Appwrite's Pink Design, set up an Appwrite database, implement real-time updates with Appwrite, and subscribe to real-time updates. Following these steps, developers can add real-time functionality to their applications and create dynamic and engaging user experiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nuxt.com/docs/getting-started/installation" rel="noopener noreferrer"&gt;Get Started with Nuxt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pink.appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Pink Design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex" rel="noopener noreferrer"&gt;Array.prototype.findIndex() - JavaScript | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Hrdtr/nuxt-appwrite" rel="noopener noreferrer"&gt;Hrdtr/nuxt-appwrite: Easily connect Appwrite to Nuxt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>cloud</category>
      <category>appwrite</category>
    </item>
    <item>
      <title>Quickly get your app to market with these bootstrapping tips</title>
      <dc:creator>Divine Orji</dc:creator>
      <pubDate>Wed, 25 Jan 2023 10:20:57 +0000</pubDate>
      <link>https://dev.to/hackmamba/quickly-get-your-app-to-market-with-these-bootstrapping-tips-2437</link>
      <guid>https://dev.to/hackmamba/quickly-get-your-app-to-market-with-these-bootstrapping-tips-2437</guid>
      <description>&lt;p&gt;As you begin a new project, you may encounter a dizzying array of components required to build a functional product.&lt;/p&gt;

&lt;p&gt;In a highly saturated and competitive market, it is vital to create a minimum viable version of your idea as soon as possible, gather user feedback, iterate fast, and improve your product. This process ensures that your app remains relevant and meets the evolving needs of your users.&lt;/p&gt;

&lt;p&gt;This article will discuss how ready-made tools can help you bootstrap your app and quickly bring it to market. Additionally, you will get tips on utilizing these tools to achieve your development and business goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you should bootstrap your app
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/hackmamba/you-can-save-this-much-by-bootstrapping-your-backend-4if9"&gt;Bootstrapping&lt;/a&gt; a project with ready-made tools can be necessary for several reasons. Some of the main benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time savings:&lt;/strong&gt; Using ready-made tools can help you get your project off the ground more quickly, as you don't have to spend time building everything from scratch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost savings:&lt;/strong&gt; Using ready-made tools can also be more cost-effective than building everything from scratch, as you may not have to pay for the development of custom solutions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved reliability:&lt;/strong&gt; Ready-made tools are often well-tested and reliable, which can help reduce the risk of problems or bugs in your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access to a broader range of capabilities:&lt;/strong&gt; By using ready-made tools, you can take advantage of a broader range of capabilities that may be challenging to build on your own.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tips for effectively bootstrapping your app
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identify your target market:&lt;/strong&gt; Clearly define the audience you're targeting with your app. This will help you focus your efforts and ensure that your app meets the needs and interests of your target market.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define your app’s features:&lt;/strong&gt; Determine the core features that your app will offer and prioritize them based on their importance to your target market. This will help you focus your development efforts and ensure that your app delivers value to your users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test and iterate:&lt;/strong&gt; Once you have a working prototype of your app, it's essential to test it with a small group of users to gather feedback and identify any issues. Use this feedback to iterate and improve your app before launching it to the general public.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Build a marketing plan:&lt;/strong&gt; Develop a marketing plan to help you effectively promote your app to your audience. This may include social media marketing, content marketing, email marketing, and other tactics.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to bootstrap your app with Appwrite
&lt;/h2&gt;

&lt;p&gt;Appwrite is an open-source Backend-as-a-Service (BaaS) that abstracts and simplifies everyday development tasks behind APIs.&lt;/p&gt;

&lt;p&gt;It provides ready-to-use features such as localization, cloud storage, serverless functions, authentication, and databases, significantly reducing the time it takes to build advanced apps.&lt;br&gt;
Appwrite also allows you to self-host, guaranteeing complete data privacy while providing end-to-end security for your backend APIs.&lt;/p&gt;

&lt;p&gt;With Appwrite, you can outsource the responsibilities of running and maintaining servers, allowing you to focus on the front-end or client-side development.&lt;/p&gt;

&lt;p&gt;To bootstrap your app with Appwrite, start by navigating to &lt;a href="https://appwrite.io" rel="noopener noreferrer"&gt;appwrite.io&lt;/a&gt; in your preferred browser and clicking &lt;strong&gt;Get Started&lt;/strong&gt;. You can install it using Docker or click on the available options in &lt;strong&gt;Next Steps&lt;/strong&gt; to view their specific documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_70D8E1C2201B1938D201DA99EE72044AE30E10576A3142C7FBF058398727219D_1671860794939_Untitled-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_70D8E1C2201B1938D201DA99EE72044AE30E10576A3142C7FBF058398727219D_1671860794939_Untitled-min.png" alt="Installing Appwrite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, you explored how Appwrite handles your app's backend so you can focus on getting to the market as soon as possible. Overall, using ready-made tools can be a practical and efficient way to get a project off the ground and ensure that it has the features and capabilities you need to succeed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.techtarget.com/searchcloudcomputing/definition/Software-as-a-Service" rel="noopener noreferrer"&gt;What is SaaS (Software as a Service)? Everything You Need to Know&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.ibm.com/cloud/blog/top-5-advantages-of-software-as-a-service" rel="noopener noreferrer"&gt;Top 5 Advantages of Software as a Service (SaaS) | IBM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.apogaeis.com/blog/4-ways-saas-software-as-a-service-can-help-in-your-business-growth/" rel="noopener noreferrer"&gt;4 Ways SaaS (Software-as-a-Service) can Help in Your Business Growth&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>appwrite</category>
      <category>baas</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Best Cron Alternative You're Not Using</title>
      <dc:creator>Divine Orji</dc:creator>
      <pubDate>Mon, 21 Nov 2022 16:31:21 +0000</pubDate>
      <link>https://dev.to/hackmamba/best-cron-alternative-youre-not-using-22f</link>
      <guid>https://dev.to/hackmamba/best-cron-alternative-youre-not-using-22f</guid>
      <description>&lt;p&gt;Cron is a time-based scheduler for Unix-like operating systems. Developers use cron jobs to automate database maintenance activities, perform general chores, and set up schedules for things like notifications or reminders.&lt;/p&gt;

&lt;p&gt;As a developer, if you’re using a popular content management system like WordPress or Drupal, chances are good that it comes with built-in support for cron jobs. However, if you’re building from scratch, you may notice issues when running cron jobs on your server.&lt;/p&gt;

&lt;p&gt;In this article, you will see some of these issues and learn about a suitable alternative to Cron: Appwrite.&lt;/p&gt;

&lt;h2&gt;
  
  
  How A Cron Job Works
&lt;/h2&gt;

&lt;p&gt;On a Linux or macOS (*nix) server, the cron command line interface runs instructions from a &lt;code&gt;crontab&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_9EB9EFC49124C45013E8CEE34C86B033078BE38F08BB019B033A13067329BD04_1666169902152_Screenshot%2B2022-10-19%2B095521-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_9EB9EFC49124C45013E8CEE34C86B033078BE38F08BB019B033A13067329BD04_1666169902152_Screenshot%2B2022-10-19%2B095521-min.png" alt="Cron syntax"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These instructions follow a specific format:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Five fields represent the &lt;code&gt;minute&lt;/code&gt;, &lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;day of month&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, and &lt;code&gt;day of week&lt;/code&gt; for your task to run. There’s an optional sixth field for &lt;code&gt;year&lt;/code&gt;, but developers rarely use it&lt;/li&gt;
&lt;li&gt;By default, each field contains the &lt;code&gt;*&lt;/code&gt; symbol, also known as a “wildcard”. If, for example, it is on the “month” field, it will run your set command every month of the year&lt;/li&gt;
&lt;li&gt;Your server’s username&lt;/li&gt;
&lt;li&gt;The command you want to execute&lt;/li&gt;
&lt;li&gt;The time settings, username, and command are all separated by spaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if you want to write a command to add some text to a file at 2:45 am every Tuesday, you will first run this command in your server’s terminal to open your &lt;code&gt;crontab&lt;/code&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

crontab &lt;span class="nt"&gt;-e&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Then add this text to the file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

45 2 * * 2 username echo "some new text" &amp;gt;&amp;gt; path-to-file/file-name


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

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;username&lt;/code&gt; is usually &lt;code&gt;root&lt;/code&gt;, but you can specify a different username as required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why You Shouldn’t Use Cron
&lt;/h2&gt;

&lt;p&gt;Cron was created in the 1970s and has since evolved, but it remains a niche tool that is not always appropriate for every use case.&lt;br&gt;
For example, it is possible to mismatch timezones when setting up a cron job, causing your command to run at a different time than expected.&lt;br&gt;
Some other reasons why you do not need to use cron include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It has no auto-retry mechanism, so if your server stops or restarts, your cron job will not run until its next interval&lt;/li&gt;
&lt;li&gt;You have to specify a new line at the end of your &lt;code&gt;crontab&lt;/code&gt; file, or your command will not run&lt;/li&gt;
&lt;li&gt;In many environments, cron executes commands with &lt;code&gt;sh&lt;/code&gt; instead of &lt;code&gt;bash&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You cannot schedule a task to the exact second with a cron job. The shortest possible time in a cron syntax is one minute&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Appwrite: An Alternative To Cron
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fappwrite.io%2Fimages%2Flogo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fappwrite.io%2Fimages%2Flogo.png" alt="Appwrite - Open-source backend-as-a-service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Appwrite&lt;/a&gt; is an open-source backend-as-a-service platform that offers a set of REST APIs to help you meet your basic backend needs. You can add features like authentication, cloud services, databases, file storage, and webhooks to your application without starting from scratch. You can also extend Appwrite’s capabilities using your favorite backend language.&lt;/p&gt;

&lt;p&gt;One of Appwrite’s services—&lt;a href="https://appwrite.io/docs/functions" rel="noopener noreferrer"&gt;Cloud Functions&lt;/a&gt;—executes your custom code in response to system events like creating an account, logging in, or document update.&lt;br&gt;
It also allows you to schedule serverless functions using a cron syntax or manually trigger them via an HTTP endpoint.&lt;br&gt;
Appwrite runs your functions in a secure, isolated Docker container and supports multiple runtimes for different backend languages.&lt;/p&gt;

&lt;p&gt;Scheduling your tasks using Appwrite Functions has some unique advantages over traditional cron, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can write backend functions and deploy them without fully managing any infrastructure. Appwrite’s reliable cloud services ensure that your servers perform optimally 99.9% of the time&lt;/li&gt;
&lt;li&gt;Appwrite manages scheduling for you on its platform, which means that in the rare event your task misses its schedule, it automatically retries it&lt;/li&gt;
&lt;li&gt;Instead of dealing with inconsistent timezones, wrong crontab notations, or manually restarting your cron after a server update, you can easily set up your task schedules in Appwrite’s delightful user interface and achieve the same results or better&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Scheduling Tasks With Appwrite Functions
&lt;/h2&gt;

&lt;p&gt;To schedule a task, create a serverless function in your preferred backend language and deploy it to Appwrite.&lt;br&gt;
On the sidebar of your Appwrite dashboard, click on “Functions”, select the function you have created, and go to its settings.&lt;br&gt;
When you scroll down, you will see “Schedule (CRON Syntax)”, which enables you to set a schedule for your function or task:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_9EB9EFC49124C45013E8CEE34C86B033078BE38F08BB019B033A13067329BD04_1666241143005_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropboxusercontent.com%2Fs_9EB9EFC49124C45013E8CEE34C86B033078BE38F08BB019B033A13067329BD04_1666241143005_image.png" alt="Scheduling with Appwrite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can set the &lt;code&gt;minute&lt;/code&gt;, &lt;code&gt;hour&lt;/code&gt;, &lt;code&gt;day of month&lt;/code&gt;, &lt;code&gt;month&lt;/code&gt;, and &lt;code&gt;day of week&lt;/code&gt; based on the original cron syntax.&lt;br&gt;
After setting up your schedule, click the “Update” button below, then sit back and watch it execute reliably with no extra supervision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, you learned about task scheduling using cron and how to set it up on Appwrite Functions. You also discovered some benefits of using Appwrite Functions instead of traditional cron.&lt;br&gt;
Take advantage of Appwrite’s full range of backend services, including database, file storage, and user authentication, to build and scale your application.&lt;br&gt;
Click &lt;a href="https://appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;here&lt;/a&gt; to get started.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://www.freepik.com/free-vector/man-moving-clock-arrows-managing-time_11235693.htm#query=time&amp;amp;position=3&amp;amp;from_view=keyword" rel="noopener noreferrer"&gt;Cover image by pch.vector&lt;/a&gt; on Freepik&lt;/p&gt;

</description>
      <category>appwrite</category>
      <category>serverless</category>
      <category>programming</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Quickly Create a Responsive Sales Data Table with Vue and Vuetify</title>
      <dc:creator>Divine Orji</dc:creator>
      <pubDate>Mon, 26 Sep 2022 00:11:37 +0000</pubDate>
      <link>https://dev.to/hackmamba/quickly-create-a-responsive-sales-data-table-with-vue-and-vuetify-i3d</link>
      <guid>https://dev.to/hackmamba/quickly-create-a-responsive-sales-data-table-with-vue-and-vuetify-i3d</guid>
      <description>&lt;p&gt;When running a business, taking advantage of insights in your sales data provides an ingenious way to make better business decisions.&lt;/p&gt;

&lt;p&gt;In this article, you will learn how to create a sales data table in Vue and Vuetify and store your data using Appwrite.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vuetifyjs.com/" rel="noopener noreferrer"&gt;Vuetify&lt;/a&gt; is a modern UI library built on Vue, with design patterns and principles based on Google’s Material UI. It provides many responsive components out of the box, speeding up your development process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://appwrite.io/?utm_source=hackmamba&amp;amp;utm_medium=hackmamba-blog" rel="noopener noreferrer"&gt;Appwrite&lt;/a&gt; is a backend-as-a-service platform that enables you to integrate features such as storage, authentication, and database management into your project without having to build a backend from scratch.&lt;/p&gt;

&lt;h2&gt;
  
  
  GitHub Repo
&lt;/h2&gt;

&lt;p&gt;Check out its source code on &lt;a href="https://github.com/dpkreativ/appwrite-sales-data-table" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow along and understand this article, you should have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of JavaScript and Vue.js&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cli.vuejs.org/" rel="noopener noreferrer"&gt;Vue CLI&lt;/a&gt; installed on your computer. Verify its installation by running &lt;code&gt;vue --version&lt;/code&gt; in your terminal, or install it by running &lt;code&gt;npm install --location=global @vue/cli&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Docker Desktop installed on your computer. Run &lt;code&gt;docker -v&lt;/code&gt; in your terminal to verify its installation, or install it by following the steps outlined in the &lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Get Docker documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Appwrite instance running on Docker. Follow &lt;a href="https://dev.to/hackmamba/create-a-local-appwrite-instance-in-3-steps-19n9?utm_source=hackmamba&amp;amp;utm_medium=hackmamba"&gt;this guide&lt;/a&gt; to create a local Appwrite instance&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up Your Vue Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create your project
&lt;/h3&gt;

&lt;p&gt;In your terminal, navigate to your preferred directory and run the command below to create a new &lt;code&gt;vue&lt;/code&gt; project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue create &amp;lt;project-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this article, &lt;code&gt;&amp;lt;project-name&amp;gt;&lt;/code&gt; is &lt;code&gt;appwrite-sales-data-table&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the options to pick a preset, select &lt;code&gt;Default ([Vue2] babel, eslint)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Vuetify
&lt;/h3&gt;

&lt;p&gt;After successfully creating your Vue project, &lt;code&gt;cd&lt;/code&gt; into it and run the command below to install Vuetify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue add vuetify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the options to choose a preset, select &lt;code&gt;Vuetify 2 - Vue CLI (recommended)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After its successful installation, run &lt;code&gt;npm run serve&lt;/code&gt; in your terminal and view your newly created Vue/Vuetify project in your browser at &lt;code&gt;localhost:8080&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042661974_Untitled-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042661974_Untitled-min.png" alt="Vuetify Home"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Table UI
&lt;/h2&gt;

&lt;p&gt;In Vuetify, you can use the &lt;a href="https://vuetifyjs.com/en/components/data-tables/" rel="noopener noreferrer"&gt;&lt;code&gt;v-data-table&lt;/code&gt; component&lt;/a&gt; to display tabular data. It contains APIs and props that enable you to use features such as sorting, searching, row selection, content editing, and pagination.&lt;/p&gt;

&lt;p&gt;Open your project in your code editor and update &lt;code&gt;src/App.vue&lt;/code&gt; with the code below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/dpkreativ/64768eb5f32c553ac7728e0caa19cb9c" rel="noopener noreferrer"&gt;https://gist.github.com/dpkreativ/64768eb5f32c553ac7728e0caa19cb9c&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the code above, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created a &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; with a &lt;code&gt;&amp;lt;v-app&amp;gt;&lt;/code&gt; component which wraps all your HTML content. This component is essential because it gives you access to all the capabilities of Vuetify&lt;/li&gt;
&lt;li&gt;In your &lt;code&gt;&amp;lt;v-app&amp;gt;&lt;/code&gt; component, you created another &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; containing &lt;code&gt;&amp;lt;v-data-table&amp;gt;&lt;/code&gt;, the Vuetify data table component. It contains &lt;code&gt;:headers="headers"&lt;/code&gt; and &lt;code&gt;:items="sales"&lt;/code&gt; for your table’s header and body content&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;&amp;lt;v-dialog&amp;gt;&lt;/code&gt; tag enables you to create a dialog box. In this code, you created dialog boxes to add new sales data and confirm if you want to delete existing data&lt;/li&gt;
&lt;li&gt;The data object in your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag contains the default state for your dialog boxes, headers, and sales content. The &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag also contains CRUD methods to populate your sales array and create/delete items from your table&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In your browser, your project should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042839233_Untitled%2B1-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042839233_Untitled%2B1-min.png" alt="Sales Data Table UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Your Database On Appwrite
&lt;/h2&gt;

&lt;p&gt;First, ensure that Docker Desktop is running your local Appwrite instance, then open &lt;code&gt;localhost:80&lt;/code&gt; in your browser to sign into Appwrite’s console:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1664149291304_image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1664149291304_image.png" alt="Login to Appwrite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on “Create Project” to set up a new project for your database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042935346_Untitled%2B2-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042935346_Untitled%2B2-min.png" alt="Create Project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your new project’s dashboard, click on “Database” located on the left sidebar, then click on “Add Database” to create a new database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042999526_Untitled%2B3-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662042999526_Untitled%2B3-min.png" alt="Add Database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your newly-created database, click on “Add Collection” and give your collection a suitable name:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043078447_Untitled%2B4-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043078447_Untitled%2B4-min.png" alt="Add Collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your newly-created collection, click “Attributes” and add each key in your data object as an attribute.&lt;/p&gt;

&lt;p&gt;For this project, you will create attributes for &lt;code&gt;rep&lt;/code&gt; (string), &lt;code&gt;item&lt;/code&gt; (string), &lt;code&gt;quantity&lt;/code&gt; (integer), and &lt;code&gt;price&lt;/code&gt; (float or double).&lt;/p&gt;

&lt;p&gt;Here is for &lt;code&gt;rep&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043239968_Untitled%2B5-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043239968_Untitled%2B5-min.png" alt="rep attribute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is for &lt;code&gt;quantity&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043267820_Untitled%2B6-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043267820_Untitled%2B6-min.png" alt="quantity attribute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the complete list of attributes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043295335_Untitled%2B7-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043295335_Untitled%2B7-min.png" alt="All attributes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on “Documents”, then click “Add Document” to add some data to your database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043345872_Untitled%2B8-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043345872_Untitled%2B8-min.png" alt="Add Document"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your “Documents” screen will look similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043386508_Untitled%2B9-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043386508_Untitled%2B9-min.png" alt="Documents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on “Settings” and scroll down to “Permissions”. At the “Collection Level” section, set “Read Access” and “Write Access” to &lt;code&gt;role:all&lt;/code&gt;, then click on “Update”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043522132_Untitled%2B10-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662043522132_Untitled%2B10-min.png" alt="Read and Write Access"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating Appwrite With Your Vue/Vuetify Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Appwrite’s Web SDK
&lt;/h3&gt;

&lt;p&gt;In your project’s terminal, run the command below to install Appwrite’s Web SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add appwrite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After its successful installation, create a &lt;code&gt;utils/config.js&lt;/code&gt; file in your project’s &lt;code&gt;src/&lt;/code&gt; folder and update it with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VUE_APP_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VUE_APP_PROJECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VUE_APP_COLLECTION_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VUE_APP_DATABASE_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, you created a &lt;code&gt;Server&lt;/code&gt; object that contains your Appwrite’s database secrets. These details are stored in a &lt;code&gt;.env.local&lt;/code&gt; file, and you will use them to configure Appwrite for your Vue/Vuetify project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Appwrite’s Account, Client, and Databases
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;src/&lt;/code&gt; folder, create an &lt;code&gt;api/index.js&lt;/code&gt; file and update it with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/utils/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Appwrite&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Databases&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;appwrite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;sdk&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sdk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sdk&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;appwrite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Appwrite&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setEndpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;setProject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Databases&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sdk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;appwrite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;getAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAnonymousSession&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;createDocument&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;unique()&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;listDocuments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listDocuments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;deleteDocument&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;documentId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deleteDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;documentId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imported your Appwrite secrets from &lt;code&gt;Server&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Imported &lt;code&gt;Account&lt;/code&gt;, &lt;code&gt;Client&lt;/code&gt; as &lt;code&gt;Appwrite&lt;/code&gt;, and &lt;code&gt;Databases&lt;/code&gt; from Appwrite (these give you access to Appwrite’s account authentication and database features)&lt;/li&gt;
&lt;li&gt;Created an &lt;code&gt;api&lt;/code&gt; object with two keys - &lt;code&gt;sdk&lt;/code&gt; and &lt;code&gt;provider&lt;/code&gt; (by default, &lt;code&gt;sdk&lt;/code&gt; is null, meaning it does not contain an &lt;code&gt;account&lt;/code&gt; and &lt;code&gt;database&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Your &lt;code&gt;provider&lt;/code&gt; first checks if &lt;code&gt;sdk&lt;/code&gt; is not null, in which case it returns whatever is in it. If the &lt;code&gt;sdk&lt;/code&gt; is still null, it skips the &lt;code&gt;if&lt;/code&gt; statement and runs the next code block&lt;/li&gt;
&lt;li&gt;You created an &lt;code&gt;Appwrite&lt;/code&gt; instance and set its endpoint and project ID with secrets from your &lt;code&gt;Server&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You created an &lt;code&gt;Account&lt;/code&gt; instance, which you used in &lt;code&gt;getAccount()&lt;/code&gt; to create an anonymous user session&lt;/li&gt;
&lt;li&gt;You created a &lt;code&gt;Databases&lt;/code&gt; instance, which contains your database ID and used it to perform CRUD operations in &lt;code&gt;createDocument()&lt;/code&gt;, &lt;code&gt;listDocuments()&lt;/code&gt;, and &lt;code&gt;deleteDocument()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You exported your &lt;code&gt;api&lt;/code&gt; to use in your Vue project&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add Appwrite’s secrets to .env.local file
&lt;/h3&gt;

&lt;p&gt;In your project’s root directory, create a &lt;code&gt;.env.local&lt;/code&gt; file and update it with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VUE_APP_PROJECT=yourProjectId
VUE_APP_ENDPOINT=yourApiEndpoint
VUE_APP_DATABASE_ID=yourDatabaseId
VUE_APP_COLLECTION_ID=yourCollectionId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to your project’s Appwrite console in your browser, and on the home page, click on “Settings” to view your Project ID and API Endpoint:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662045959134_Untitled%2B11-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662045959134_Untitled%2B11-min.png" alt="Project ID and API Endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on “Database” in your project’s sidebar, then open your database and click on “Settings” to view your Database ID:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046044607_Untitled%2B12-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046044607_Untitled%2B12-min.png" alt="Database ID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the “Collections” tab, select your collection and click on “Settings” to view your Collection ID:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046108007_Untitled%2B13-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046108007_Untitled%2B13-min.png" alt="Collection ID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Import Appwrite’s config files into Vue project
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;App.vue&lt;/code&gt; file, import your Appwrite config files by updating &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./utils/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// pre-existing code&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setup Authorization
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;'s &lt;code&gt;methods&lt;/code&gt; object, add the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAccount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Triggered the &lt;code&gt;getAccount()&lt;/code&gt; function in &lt;code&gt;api/index.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When Appwrite grants a user permission to access the database, it sends a response to the console or displays an error if the request is unsuccessful&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Get data from Appwrite’s database
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;'s &lt;code&gt;methods&lt;/code&gt; object, update &lt;code&gt;initialize()&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;getItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listDocuments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;getItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sales&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Triggered the &lt;code&gt;authorize()&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;Triggered the &lt;code&gt;listDocuments()&lt;/code&gt; function in &lt;code&gt;api/index.js&lt;/code&gt;. It takes in your &lt;code&gt;collectionId&lt;/code&gt; as a parameter&lt;/li&gt;
&lt;li&gt;Added the successful response to your &lt;code&gt;sales&lt;/code&gt; array, and displayed errors (if any) in your browser’s console&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run &lt;code&gt;yarn serve&lt;/code&gt; in your terminal, and refresh your browser, you will see the data you’ve already stored in your Appwrite database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046655263_Untitled%2B14-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662046655263_Untitled%2B14-min.png" alt="Updated Sales Data Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Delete Data From the Table and Appwrite Database
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;'s &lt;code&gt;methods&lt;/code&gt; object, update &lt;code&gt;deleteConfirm()&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;deleteItemConfirm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deleteDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;editedIndex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;$id&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;editedIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closeDelete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added a &lt;code&gt;try-catch&lt;/code&gt; block to trigger the &lt;code&gt;deleteDocument()&lt;/code&gt; function in &lt;code&gt;api/index.js&lt;/code&gt;. Its two parameters are your &lt;code&gt;collectionId&lt;/code&gt;, and your document’s &lt;code&gt;$id&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You also deleted the selected data from the &lt;code&gt;sales&lt;/code&gt; array and closed the “Delete” modal&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add New Data to the Table and Appwrite Database
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;'s &lt;code&gt;methods&lt;/code&gt; object, update &lt;code&gt;save()&lt;/code&gt; with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collectionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;editedItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;newItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Triggered the &lt;code&gt;createDocument()&lt;/code&gt; function in &lt;code&gt;api/index.js&lt;/code&gt;; it takes in your &lt;code&gt;collectionId&lt;/code&gt; and the new data as parameters&lt;/li&gt;
&lt;li&gt;Added the data to the &lt;code&gt;sales&lt;/code&gt; array after successfully adding it to your database.&lt;/li&gt;
&lt;li&gt;Closed your modal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662047085462_ezgif.com-gif-maker-min.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_DFAA6E4E3446FD3969F00FDE96EBB635D952D8A7BC79B79B8A162215B297EAD3_1662047085462_ezgif.com-gif-maker-min.gif" alt="Final Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the article, you learned how to create a responsive sales data table with Vue and Vuetify, store and retrieve your data using Appwrite.&lt;/p&gt;

&lt;p&gt;Combining Vuetify and Appwrite provides many robust, out-of-the-box features to enable you to build full-fledged apps quickly.&lt;/p&gt;

&lt;p&gt;To learn more about these features, check out the resources below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://appwrite.io/docs" rel="noopener noreferrer"&gt;Appwrite’s official documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=cu5pkTdWiW8&amp;amp;list=PL-nc7zI7zjsaCNC-sluNK4mHwdqk-nKEU&amp;amp;index=5" rel="noopener noreferrer"&gt;Setting up Databases and Collections in Appwrite - YouTube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/appwrite/demo-todo-with-vue" rel="noopener noreferrer"&gt;Appwrite Demo with Vue - GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>appwrite</category>
      <category>vue</category>
      <category>vuetify</category>
      <category>database</category>
    </item>
  </channel>
</rss>
