<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raihan Nismara on Medium]]></title>
        <description><![CDATA[Stories by Raihan Nismara on Medium]]></description>
        <link>https://medium.com/@raihannismara?source=rss-500caf978c5d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jdPtnIj3tnaAcCD3KWgbRA.png</url>
            <title>Stories by Raihan Nismara on Medium</title>
            <link>https://medium.com/@raihannismara?source=rss-500caf978c5d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:43:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@raihannismara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tutorial CI/CD dengan GitHub Actions ke VPS Ubuntu]]></title>
            <link>https://medium.com/@raihannismara/tutorial-ci-cd-dengan-github-actions-ke-vps-ubuntu-9698c9dae0ef?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9698c9dae0ef</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Sat, 17 Oct 2026 01:16:52 GMT</pubDate>
            <atom:updated>2026-10-17T01:16:52.644Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Materi praktikum bootcamp kuliah — dari repository kosong sampai aplikasi otomatis ter-deploy ke VPS.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y4iXlQAvNY7DI-ls" /><figcaption>Photo by <a href="https://unsplash.com/@intrapixel?utm_source=medium&amp;utm_medium=referral">intrapixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Tujuan pembelajaran</h3><p>Setelah mengikuti tutorial ini, peserta diharapkan dapat:</p><ol><li>Menjelaskan perbedaan Continuous Integration (CI) dan Continuous Delivery/Deployment (CD).</li><li>Menyiapkan VPS Ubuntu untuk menjalankan aplikasi Node.js.</li><li>Menghubungkan GitHub Actions ke VPS menggunakan SSH key.</li><li>Membuat pipeline yang menjalankan automated test sebelum deployment.</li><li>Menjalankan aplikasi memakai PM2 dan mengaksesnya melalui Nginx.</li><li>Memeriksa hasil deployment dan mendiagnosis masalah umum.</li></ol><h3>Arsitektur yang akan dibuat</h3><pre>Developer<br>   |<br>   | git push ke branch main<br>   v<br>GitHub Repository<br>   |<br>   v<br>GitHub Actions (runner sementara)<br>   |-- checkout source code<br>   |-- setup Node.js<br>   |-- npm ci<br>   |-- npm test                  &lt;-- CI<br>   |-- SSH + rsync ke VPS<br>   |-- npm ci --omit=dev di VPS<br>   |-- PM2 reload aplikasi      &lt;-- CD<br>   v<br>VPS Ubuntu<br>   |-- Nginx :80/:443<br>   |-- Node.js app :3000 (hanya localhost)<br>   |-- PM2 menjaga proses aplikasi</pre><h3>Ruang lingkup dan asumsi</h3><p>Tutorial ini menggunakan contoh aplikasi <strong>Node.js tanpa framework</strong> agar prosesnya mudah dipahami dan dapat direplikasi. Metode deployment utamanya menggunakan SSH + rsync, bukan Docker.</p><p>Siapkan:</p><ul><li>Akun GitHub dan sebuah repository.</li><li>VPS Ubuntu 22.04 LTS atau 24.04 LTS dengan akses administrator melalui SSH atau console provider.</li><li>Alamat IP publik VPS.</li><li>Domain yang mengarah ke IP VPS (opsional untuk percobaan lewat IP, diperlukan untuk TLS/HTTPS memakai Let’s Encrypt).</li><li>Komputer lokal dengan Git dan OpenSSH client.</li></ul><blockquote><em>Ganti contoh seperti </em><em>VPS_IP, </em><em>example.com, </em><em>deploy, dan </em><em>bootcamp-app sesuai lingkungan sendiri. Jangan menyalin placeholder apa adanya ke konfigurasi final.</em></blockquote><h3>Bagian 1 — Buat aplikasi contoh</h3><h3>1.1 Struktur project</h3><p>Buat folder dengan struktur berikut:</p><pre>bootcamp-app/<br>├── .github/<br>│   └── workflows/<br>│       └── deploy.yml<br>├── src/<br>│   └── message.js<br>├── test/<br>│   └── message.test.js<br>├── ecosystem.config.cjs<br>├── .gitignore<br>├── package.json<br>├── package-lock.json      # dibuat menggunakan npm install<br>└── server.js</pre><h3>1.2 Buat .gitignore</h3><pre>node_modules/<br>.env<br>.env.*<br>!.env.example</pre><p>Jangan memasukkan file secret, private key, node_modules, atau file .env berisi rahasia ke Git. Jika project sudah memiliki .gitignore, gabungkan aturan yang relevan.</p><h3>1.3 Buat package.json</h3><pre>{<br>  &quot;name&quot;: &quot;bootcamp-app&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;private&quot;: true,<br>  &quot;description&quot;: &quot;Contoh aplikasi untuk belajar GitHub Actions dan VPS Ubuntu&quot;,<br>  &quot;main&quot;: &quot;server.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;node server.js&quot;,<br>    &quot;test&quot;: &quot;node --test&quot;<br>  },<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;&gt;=24&quot;<br>  }<br>}</pre><p>Buat lock file menggunakan versi Node.js dan npm yang sesuai:</p><pre>npm install</pre><p>Perintah ini membuat package-lock.json. <strong>Commit file </strong><strong>package-lock.json ke Git</strong> karena pipeline menggunakan npm ci untuk instalasi yang konsisten.</p><h3>1.4 Buat src/message.js</h3><pre>function getMessage(environment = process.env.NODE_ENV || &#39;development&#39;) {<br>  return {<br>    message: &#39;Hello from GitHub Actions CI/CD!&#39;,<br>    environment,<br>  };<br>}</pre><pre>module.exports = { getMessage };</pre><h3>1.5 Buat server.js</h3><pre>const http = require(&#39;node:http&#39;);<br>const { getMessage } = require(&#39;./src/message&#39;);</pre><pre>// Bind ke localhost karena trafik publik akan masuk melalui Nginx.<br>const HOST = process.env.HOST || &#39;127.0.0.1&#39;;<br>const PORT = Number(process.env.PORT || 3000);</pre><pre>const server = http.createServer((req, res) =&gt; {<br>  res.setHeader(&#39;Content-Type&#39;, &#39;application/json; charset=utf-8&#39;);</pre><pre>  if (req.url === &#39;/health&#39;) {<br>    res.writeHead(200);<br>    res.end(JSON.stringify({ status: &#39;ok&#39; }));<br>    return;<br>  }</pre><pre>  if (req.url === &#39;/&#39;) {<br>    res.writeHead(200);<br>    res.end(JSON.stringify(getMessage()));<br>    return;<br>  }</pre><pre>  res.writeHead(404);<br>  res.end(JSON.stringify({ message: &#39;Not found&#39; }));<br>});</pre><pre>server.listen(PORT, HOST, () =&gt; {<br>  console.log(`Server running at <a href="http://${HOST}:${PORT}`);">http://${HOST}:${PORT}`);</a><br>});</pre><h3>1.6 Buat unit test: test/message.test.js</h3><pre>const test = require(&#39;node:test&#39;);<br>const assert = require(&#39;node:assert/strict&#39;);<br>const { getMessage } = require(&#39;../src/message&#39;);</pre><pre>test(&#39;getMessage returns the expected message&#39;, () =&gt; {<br>  assert.deepEqual(getMessage(&#39;test&#39;), {<br>    message: &#39;Hello from GitHub Actions CI/CD!&#39;,<br>    environment: &#39;test&#39;,<br>  });<br>});</pre><p>Jalankan test di komputer lokal:</p><pre>npm test</pre><p>Test harus berhasil sebelum melanjutkan.</p><h3>1.7 Buat konfigurasi PM2: ecosystem.config.cjs</h3><pre>module.exports = {<br>  apps: [<br>    {<br>      name: &#39;bootcamp-app&#39;,<br>      cwd: &#39;/home/deploy/apps/bootcamp-app&#39;,<br>      script: &#39;server.js&#39;,<br>      instances: 1,<br>      exec_mode: &#39;fork&#39;,<br>      autorestart: true,<br>      watch: false,<br>      max_memory_restart: &#39;200M&#39;,<br>      env: {<br>        NODE_ENV: &#39;production&#39;,<br>        HOST: &#39;127.0.0.1&#39;,<br>        PORT: 3000,<br>      },<br>    },<br>  ],<br>};</pre><p>cwd harus sama dengan direktori deployment di VPS. Pada tutorial ini lokasinya /home/deploy/apps/bootcamp-app.</p><h3>1.8 Simpan kode ke GitHub</h3><pre>git init<br>git add .<br>git commit -m &quot;Create Node.js demo app&quot;<br>git branch -M main<br>git remote add origin https://github.com/USERNAME/REPOSITORY.git<br>git push -u origin main</pre><p>Buat repository di GitHub terlebih dahulu, lalu ganti USERNAME/REPOSITORY dengan alamat repository milik Anda. Bila repository sudah memakai Git, tidak perlu menjalankan git init lagi.</p><h3>Bagian 2 — Siapkan VPS Ubuntu</h3><h3>2.1 Login dan perbarui sistem</h3><p>Dari komputer lokal, login memakai akun administrator yang disediakan provider:</p><pre>ssh ADMIN_USER@VPS_IP</pre><p>Lalu jalankan:</p><pre>sudo apt update<br>sudo apt upgrade -y<br>sudo apt install -y nginx curl ca-certificates gnupg rsync</pre><p>Pastikan akses SSH tetap tersedia selama konfigurasi firewall. Pada VPS cloud, periksa juga aturan firewall/security group di dashboard provider.</p><h3>2.2 Buat user khusus deployment</h3><p>Hindari menjalankan proses deployment sebagai root. Buat user khusus bernama deploy:</p><pre>sudo adduser --disabled-password --gecos &quot;&quot; deploy<br>sudo install -d -o deploy -g deploy -m 755 /home/deploy/apps/bootcamp-app</pre><p>User deploy tidak perlu menjadi anggota grup sudo untuk contoh ini. Tujuannya membatasi dampak jika kredensial deployment bocor.</p><h3>2.3 Install Node.js LTS dan PM2</h3><p>Contoh ini menggunakan Node.js 24 LTS. Ikuti juga instruksi resmi Node.js atau penyedia paket tepercaya bila metode instalasi di lingkungan Anda berbeda.</p><pre>curl -fsSL https://deb.nodesource.com/setup_24.x -o /tmp/nodesource_setup.sh<br>sudo -E bash /tmp/nodesource_setup.sh<br>sudo apt-get install -y nodejs</pre><p>Verifikasi:</p><pre>node --version<br>npm --version</pre><p>Install PM2 secara global:</p><pre>sudo npm install --global pm2<br>pm2 --version</pre><p>PM2 mengelola proses Node.js supaya aplikasi dapat dijalankan kembali jika crash dan dapat dikonfigurasi untuk hidup kembali setelah reboot.</p><h3>2.4 Pastikan Nginx aktif</h3><pre>sudo systemctl enable --now nginx<br>sudo systemctl status nginx --no-pager</pre><p>Jika firewall UFW belum dikonfigurasi, perbolehkan SSH dan trafik web sebelum mengaktifkannya:</p><pre>sudo ufw allow OpenSSH<br>sudo ufw allow &#39;Nginx Full&#39;<br>sudo ufw status<br>sudo ufw enable</pre><blockquote><em>Penting: jangan mengaktifkan UFW sebelum memastikan aturan SSH benar. Anda juga harus membuka port TCP 22 (atau port SSH yang Anda gunakan), 80, dan 443 pada firewall/security group provider. Jangan membuka port aplikasi 3000 ke publik; aplikasi akan diakses melalui Nginx.</em></blockquote><h3>Bagian 3 — Siapkan autentikasi SSH dari GitHub Actions</h3><p>GitHub Actions perlu terhubung ke VPS tanpa meminta password saat workflow berjalan. Kita menggunakan SSH key khusus untuk user deploy.</p><h3>3.1 Buat SSH key di komputer lokal</h3><p>Jalankan <strong>di komputer lokal, bukan di VPS</strong>:</p><pre>mkdir -p &quot;$HOME/.ssh&quot;<br>chmod 700 &quot;$HOME/.ssh&quot;<br>ssh-keygen -t ed25519 -C &quot;github-actions-bootcamp-deploy&quot; -f &quot;$HOME/.ssh/github_actions_deploy&quot; -N &quot;&quot;</pre><p>Perintah tersebut menghasilkan dua file:</p><ul><li>$HOME/.ssh/github_actions_deploy — private key; rahasiakan file ini.</li><li>$HOME/.ssh/github_actions_deploy.pub — public key; boleh dipasang di VPS.</li></ul><p>Jangan commit kedua file tersebut ke repository. Jangan pernah menaruh private key ke file workflow, source code, atau dokumentasi publik.</p><h3>3.2 Pasang public key pada user deploy</h3><p>Tampilkan public key di komputer lokal:</p><pre>cat &quot;$HOME/.ssh/github_actions_deploy.pub&quot;</pre><p>Salin satu baris yang dihasilkan. Di sesi SSH administrator pada VPS, masukkan public key tersebut dengan mengganti placeholder berikut:</p><pre>sudo install -d -o deploy -g deploy -m 700 /home/deploy/.ssh<br>printf &#39;%s\n&#39; &#39;PASTE_PUBLIC_KEY_HERE&#39; | sudo tee -a /home/deploy/.ssh/authorized_keys &gt;/dev/null<br>sudo chown deploy:deploy /home/deploy/.ssh/authorized_keys<br>sudo chmod 600 /home/deploy/.ssh/authorized_keys</pre><p>Pastikan hasil cat &quot;$HOME/.ssh/github_actions_deploy.pub&quot; disalin utuh, dimulai dengan ssh-ed25519 dan diakhiri komentar key. Jangan memasukkan private key pada langkah ini.</p><h3>3.3 Uji SSH dari komputer lokal</h3><pre>ssh -i &quot;$HOME/.ssh/github_actions_deploy&quot; deploy@VPS_IP</pre><p>Pada koneksi pertama, SSH biasanya meminta konfirmasi host key. Sebelum menyetujuinya, verifikasi fingerprint host VPS melalui console/provider atau saluran tepercaya lain. Setelah berhasil login, keluar dengan exit.</p><h3>3.4 Siapkan known_hosts dengan verifikasi fingerprint</h3><p>Workflow akan memeriksa identitas host SSH. Jangan mengatasi masalah host key dengan StrictHostKeyChecking=no.</p><p>Di console tepercaya VPS, tampilkan fingerprint public host key:</p><pre>sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub</pre><p>Di komputer lokal, ambil host key menggunakan host dan port yang benar-benar akan dipakai oleh GitHub Actions. Contoh port default 22:</p><pre>ssh-keyscan -p 22 VPS_IP &gt; &quot;$HOME/.ssh/known_hosts_temp&quot;<br>ssh-keygen -lf &quot;$HOME/.ssh/known_hosts_temp&quot;</pre><p>Bandingkan fingerprint hasilnya dengan fingerprint dari console VPS. <strong>Jangan lanjutkan jika fingerprint tidak cocok.</strong> Setelah cocok, buat daftar known hosts berformat hash:</p><pre>ssh-keyscan -H -p 22 VPS_IP &gt; &quot;$HOME/.ssh/github_actions_known_hosts&quot;</pre><p>Jika VPS memakai port SSH non-standar, ganti 22 dengan port tersebut. Gunakan hostname/IP yang sama dengan nilai VPS_HOST pada GitHub Secrets. Verifikasi fingerprint untuk file hasil scan itu juga.</p><blockquote><em>ssh-keyscan hanya mengambil public host key; ia tidak membuktikan bahwa server tersebut benar. Verifikasi fingerprint melalui jalur tepercaya sebelum menyimpan hasilnya.</em></blockquote><h3>Bagian 4 — Tambahkan GitHub Secrets</h3><p>Di repository GitHub, buka <strong>Settings → Secrets and variables → Actions → New repository secret</strong>. Buat secrets berikut:</p><p>Nama secretNilaiVPS_HOSTIP publik atau hostname VPS, misalnya 203.0.113.10VPS_PORTPort SSH, biasanya 22VPS_USERdeployVPS_SSH_KEYSeluruh isi private key dari github_actions_deployVPS_KNOWN_HOSTSSeluruh isi $HOME/.ssh/github_actions_known_hosts yang fingerprint-nya sudah diverifikasi</p><p>Private key memiliki format mirip berikut. Simpan isi sebenarnya sebagai secret, jangan mengganti nilainya dengan contoh ini:</p><pre>-----BEGIN OPENSSH PRIVATE KEY-----<br>[baris private key]<br>-----END OPENSSH PRIVATE KEY-----</pre><p>Secret adalah variabel sensitif yang disimpan di pengaturan repository dan diakses workflow menggunakan ekspresi ${{ secrets.NAMA_SECRET }}. Hindari mencetak secret ke log.</p><h3>Bagian 5 — Buat workflow GitHub Actions</h3><p>Buat file .github/workflows/deploy.yml pada repository.</p><pre>name: CI/CD to Ubuntu VPS</pre><pre>on:<br>  push:<br>    branches:<br>      - main<br>  workflow_dispatch:</pre><pre>permissions:<br>  contents: read</pre><pre># Mencegah dua deployment production berjalan bersamaan.<br>concurrency:<br>  group: production-deploy<br>  cancel-in-progress: false</pre><pre>jobs:<br>  test-and-deploy:<br>    name: Test and deploy<br>    runs-on: ubuntu-latest<br>    timeout-minutes: 15</pre><pre>    env:<br>      VPS_HOST: ${{ secrets.VPS_HOST }}<br>      VPS_PORT: ${{ secrets.VPS_PORT }}<br>      VPS_USER: ${{ secrets.VPS_USER }}<br>      DEPLOY_PATH: /home/deploy/apps/bootcamp-app</pre><pre>    steps:<br>      - name: Checkout repository<br>        uses: actions/checkout@v7</pre><pre>      - name: Set up Node.js<br>        uses: actions/setup-node@v7<br>        with:<br>          node-version: &#39;24&#39;<br>          cache: npm</pre><pre>      - name: Install dependencies<br>        run: npm ci</pre><pre>      - name: Run tests<br>        run: npm test</pre><pre>      - name: Prepare SSH credentials<br>        env:<br>          SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_KEY }}<br>          SSH_KNOWN_HOSTS: ${{ secrets.VPS_KNOWN_HOSTS }}<br>        shell: bash<br>        run: |<br>          set -euo pipefail<br>          install -m 700 -d &quot;$HOME/.ssh&quot;<br>          printf &#39;%s\n&#39; &quot;$SSH_PRIVATE_KEY&quot; &gt; &quot;$HOME/.ssh/id_ed25519&quot;<br>          chmod 600 &quot;$HOME/.ssh/id_ed25519&quot;<br>          printf &#39;%s\n&#39; &quot;$SSH_KNOWN_HOSTS&quot; &gt; &quot;$HOME/.ssh/known_hosts&quot;<br>          chmod 644 &quot;$HOME/.ssh/known_hosts&quot;</pre><pre>      - name: Install rsync on runner<br>        run: |<br>          sudo apt-get update<br>          sudo apt-get install -y rsync</pre><pre>      - name: Verify VPS connection<br>        shell: bash<br>        run: |<br>          set -euo pipefail<br>          ssh \<br>            -p &quot;$VPS_PORT&quot; \<br>            -i &quot;$HOME/.ssh/id_ed25519&quot; \<br>            -o IdentitiesOnly=yes \<br>            -o BatchMode=yes \<br>            &quot;$VPS_USER@$VPS_HOST&quot; \<br>            &#39;printf &quot;SSH connection OK\n&quot;; command -v rsync; node --version; npm --version; pm2 --version&#39;</pre><pre>      - name: Sync files to VPS<br>        shell: bash<br>        run: |<br>          set -euo pipefail<br>          rsync -az --delete \<br>            --exclude=&#39;.git/&#39; \<br>            --exclude=&#39;node_modules/&#39; \<br>            --exclude=&#39;.env&#39; \<br>            --exclude=&#39;.env.*&#39; \<br>            -e &quot;ssh -p $VPS_PORT -i $HOME/.ssh/id_ed25519 -o IdentitiesOnly=yes -o BatchMode=yes&quot; \<br>            ./ &quot;$VPS_USER@$VPS_HOST:$DEPLOY_PATH/&quot;</pre><pre>      - name: Install production dependencies and reload app<br>        shell: bash<br>        run: |<br>          set -euo pipefail<br>          ssh \<br>            -p &quot;$VPS_PORT&quot; \<br>            -i &quot;$HOME/.ssh/id_ed25519&quot; \<br>            -o IdentitiesOnly=yes \<br>            -o BatchMode=yes \<br>            &quot;$VPS_USER@$VPS_HOST&quot; \<br>            &quot;DEPLOY_PATH=&#39;$DEPLOY_PATH&#39; bash -s&quot; &lt;&lt;&#39;REMOTE&#39;<br>          set -Eeuo pipefail<br>          cd &quot;$DEPLOY_PATH&quot;</pre><pre>          # Install only production dependencies on the VPS.<br>          npm ci --omit=dev</pre><pre>          # Start the process for the first deployment, or reload it afterwards.<br>          pm2 startOrReload ecosystem.config.cjs --update-env<br>          pm2 save</pre><pre>          # Wait briefly for the app and check its health endpoint.<br>          healthy=0<br>          for attempt in 1 2 3 4 5; do<br>            if curl --fail --silent --show-error <a href="http://127.0.0.1:3000/health;">http://127.0.0.1:3000/health;</a> then<br>              healthy=1<br>              break<br>            fi<br>            sleep 2<br>          done</pre><pre>          if [ &quot;$healthy&quot; -ne 1 ]; then<br>            echo &quot;Health check failed. Recent PM2 logs:&quot; &gt;&amp;2<br>            pm2 logs bootcamp-app --lines 80 --nostream &gt;&amp;2 || true<br>            exit 1<br>          fi<br>          REMOTE</pre><h3>Apa yang dilakukan workflow tersebut?</h3><ol><li><strong>Trigger:</strong> workflow berjalan ketika ada push ke branch main, atau saat dijalankan secara manual melalui workflow_dispatch.</li><li><strong>Checkout:</strong> mengambil source code dari repository.</li><li><strong>Setup Node.js:</strong> menggunakan Node.js 24 pada runner GitHub.</li><li><strong>CI:</strong> menjalankan npm ci dan npm test. Jika test gagal, langkah deployment berikutnya tidak dijalankan.</li><li><strong>Autentikasi SSH:</strong> membuat file private key dan known hosts dari GitHub Secrets.</li><li><strong>Transfer:</strong> rsync mengirim file ke direktori aplikasi di VPS.</li><li><strong>CD:</strong> VPS memasang dependency production dan PM2 menjalankan atau me-reload aplikasi.</li><li><strong>Health check:</strong> workflow mengecek endpoint /health; workflow dianggap gagal jika aplikasi tidak sehat.</li></ol><blockquote><strong><em>Peringatan tentang </em></strong><strong><em>rsync --delete:</em></strong><em> opsi ini menghapus file di tujuan yang tidak ada pada sumber, selain file yang dikecualikan. Jangan menyimpan upload pengguna, database, atau data persisten di direktori deployment ini. Simpan data tersebut di lokasi terpisah. File </em><em>.env juga dikecualikan dari sinkronisasi, tetapi contoh aplikasi belum memerlukan environment file.</em></blockquote><h3>Catatan keamanan workflow</h3><ul><li>Contoh menggunakan tag versi major (@v7) agar lebih mudah dipelajari. Untuk lingkungan production dengan persyaratan keamanan tinggi, pin action ke full commit SHA yang sudah diverifikasi dan perbarui secara terencana.</li><li>Gunakan branch protection dan batasi siapa yang boleh push/merge ke main.</li><li>Jangan pernah menjalankan kode pull request tidak tepercaya dengan secret deployment production.</li><li>GitHub Secrets tidak boleh ditampilkan lewat echo, debug logging, atau pesan error buatan.</li><li>Akun deployment hanya digunakan untuk aplikasi ini dan tidak diberi akses sudo tanpa kebutuhan yang jelas.</li></ul><h3>Bagian 6 — Konfigurasikan Nginx sebagai reverse proxy</h3><p>Aplikasi Node.js hanya mendengarkan 127.0.0.1:3000. Nginx menerima permintaan web pada port 80/443 dan meneruskannya ke Node.js.</p><p>Di VPS, buat konfigurasi:</p><pre>sudo nano /etc/nginx/sites-available/bootcamp-app</pre><p>Isi file berikut untuk tes awal lewat IP atau domain:</p><pre>server {<br>    listen 80;<br>    listen [::]:80;<br>    server_name _;</pre><pre>    location / {<br>        proxy_pass <a href="http://127.0.0.1:3000;">http://127.0.0.1:3000;</a><br>        proxy_http_version 1.1;</pre><pre>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>    }<br>}</pre><p>Aktifkan konfigurasi. Untuk VPS baru yang hanya dipakai tutorial ini, nonaktifkan default site agar request tidak diarahkan ke halaman sambutan Nginx:</p><pre>sudo ln -s /etc/nginx/sites-available/bootcamp-app /etc/nginx/sites-enabled/bootcamp-app<br>sudo rm -f /etc/nginx/sites-enabled/default<br>sudo nginx -t<br>sudo systemctl reload nginx</pre><blockquote><em>Jika VPS sudah menjalankan website lain, jangan menghapus atau menimpa konfigurasi yang sudah ada. Atur </em><em>server_name untuk domain aplikasi, periksa konfigurasi server lain, lalu reload Nginx hanya setelah </em><em>sudo nginx -t berhasil.</em></blockquote><p>Sekarang buka http://VPS_IP/ di browser. Jika workflow berhasil, respons JSON seharusnya mirip:</p><pre>{<br>  &quot;message&quot;: &quot;Hello from GitHub Actions CI/CD!&quot;,<br>  &quot;environment&quot;: &quot;production&quot;<br>}</pre><p>Cek endpoint health:</p><pre>curl -i http://VPS_IP/health</pre><p>Respons yang diharapkan: status HTTP 200 dan body {&quot;status&quot;:&quot;ok&quot;}.</p><h3>6.1 Aktifkan HTTPS jika memakai domain</h3><ol><li>Buat DNS A record untuk domain menuju IP publik VPS. Tambahkan record AAAA hanya jika IPv6 benar-benar dikonfigurasi.</li><li>Pastikan port 80 dan 443 dibuka di firewall VPS dan firewall provider.</li><li>Ganti server_name _; di konfigurasi Nginx dengan domain yang benar, misalnya example.com www.example.com, lalu jalankan sudo nginx -t &amp;&amp; sudo systemctl reload nginx.</li><li>Install Certbot dan plugin Nginx:</li></ol><pre>sudo apt update<br>sudo apt install -y certbot python3-certbot-nginx<br>sudo certbot --nginx -d example.com -d www.example.com</pre><p>Ganti nama domain dengan domain yang dikelola Anda. Ikuti prompt Certbot, lalu uji pembaruan sertifikat menggunakan sudo certbot renew --dry-run.</p><p>Jangan meminta sertifikat sebelum DNS mengarah ke VPS dan domain dapat dijangkau oleh Let’s Encrypt.</p><h3>Bagian 7 — Jalankan PM2 otomatis setelah reboot</h3><p>Setelah deployment pertama berhasil, masuk ke VPS sebagai user deploy:</p><pre>ssh deploy@VPS_IP<br>pm2 list</pre><p>Buat konfigurasi startup systemd untuk user deploy:</p><pre>pm2 startup systemd -u deploy --hp /home/deploy</pre><p>PM2 akan menampilkan perintah tambahan yang umumnya perlu dijalankan oleh administrator menggunakan sudo. Salin dan jalankan <strong>perintah yang benar-benar ditampilkan oleh PM2</strong> pada VPS, bukan menebak perintahnya.</p><p>Kemudian sebagai user deploy, simpan daftar proses:</p><pre>pm2 save</pre><p>Verifikasi:</p><pre>pm2 status<br>pm2 logs bootcamp-app --lines 50</pre><p>Setelah pengaturan startup selesai, PM2 dapat memulihkan daftar proses yang disimpan setelah reboot.</p><h3>Bagian 8 — Uji CI/CD dari awal sampai akhir</h3><h3>8.1 Commit dan push perubahan</h3><p>Ubah teks di src/message.js, misalnya:</p><pre>message: &#39;Hello, deployment otomasi berhasil!&#39;,</pre><p>Lalu jalankan:</p><pre>git add src/message.js<br>git commit -m &quot;Update application message&quot;<br>git push origin main</pre><h3>8.2 Pantau workflow</h3><ol><li>Buka repository GitHub.</li><li>Pilih tab <strong>Actions</strong>.</li><li>Buka workflow CI/CD to Ubuntu VPS.</li><li>Pastikan langkah install dependencies dan test berhasil.</li><li>Pastikan langkah SSH, rsync, reload PM2, dan health check juga berhasil.</li></ol><h3>8.3 Verifikasi di VPS</h3><pre>ssh deploy@VPS_IP<br>pm2 status<br>curl -i http://127.0.0.1:3000/health<br>curl -i http://127.0.0.1:3000/</pre><p>Atau periksa dari browser melalui http://VPS_IP/ atau domain Anda. Pastikan respons menampilkan pesan terbaru yang di-commit ke GitHub.</p><h3>8.4 Buktikan bahwa CI benar-benar menghentikan deployment ketika test gagal</h3><p>Ubah assertion test agar sengaja gagal, lalu push ke branch main di repository latihan. Amati bahwa job berhenti pada npm test dan langkah transfer/deployment tidak dijalankan. Setelah praktik, pulihkan assertion dan push ulang.</p><blockquote><em>Lakukan eksperimen test gagal hanya di lingkungan latihan, bukan ketika perubahan berisiko mengganggu layanan production.</em></blockquote><h3>Bagian 9 — Troubleshooting</h3><p>GejalaKemungkinan penyebabCara memeriksa / memperbaikiPermission denied (publickey)Public key salah, username salah, atau permission SSH keliru.Pastikan public key ada di /home/deploy/.ssh/authorized_keys, pemiliknya deploy, direktori mode 700, file mode 600, serta VPS_USER=deploy.Host key verification failedVPS_KNOWN_HOSTS salah, host/port berbeda, atau host key berubah.Verifikasi fingerprint lewat saluran tepercaya dan perbarui secret hanya setelah perubahan dianggap sah. Jangan menonaktifkan verifikasi host.npm ci gagalpackage-lock.json tidak ada/tidak cocok dengan package.json, atau versi Node.js tidak sesuai.Jalankan npm install lokal, commit lock file, kemudian samakan versi Node.js yang didukung.rsync: command not foundrsync belum terpasang pada runner atau VPS.Workflow memasang rsync di runner; jalankan sudo apt install rsync di VPS jika belum ada.PM2 tidak menemukan ecosystem.config.cjsWorkflow deploy ke folder yang berbeda dari cwd, atau sinkronisasi gagal.Pastikan DEPLOY_PATH pada workflow sama dengan cwd di konfigurasi PM2.Status Nginx 502 Bad GatewayAplikasi tidak aktif atau tidak mendengarkan di 127.0.0.1:3000.Jalankan pm2 status, pm2 logs bootcamp-app --lines 100, curl -i http://127.0.0.1:3000/health, dan sudo nginx -t.Workflow sehat tetapi situs tidak dapat diaksesPort/firewall, DNS, atau konfigurasi Nginx salah.Periksa UFW, firewall provider, DNS, sudo systemctl status nginx, dan sudo tail -n 100 /var/log/nginx/error.log.Aplikasi tidak kembali setelah rebootPM2 startup belum dikonfigurasi, atau pm2 save belum dilakukan sebagai user yang benar.Ulangi pm2 startup systemd -u deploy --hp /home/deploy dan jalankan perintah administrator yang dicetak PM2, lalu pm2 save sebagai deploy.Deployment menghapus file yang tidak diharapkanrsync --delete menghapus file di direktori tujuan yang bukan bagian dari source.Simpan file upload dan data persisten di luar direktori deployment; periksa opsi --exclude sebelum menjalankan workflow.Health check gagal pada pipelineAplikasi crash, startup lambat, port berubah, atau endpoint health tidak ada.Periksa output pm2 logs, konfigurasi PORT, dan endpoint /health.</p><p>Perintah diagnostik berguna:</p><pre>pm2 status<br>pm2 logs bootcamp-app --lines 100<br>sudo systemctl status nginx --no-pager<br>sudo nginx -t<br>sudo tail -n 100 /var/log/nginx/error.log<br>sudo ufw status</pre><h3>Bagian 10 — Praktik keamanan dan batasan metode ini</h3><p>Untuk materi bootcamp, deployment dengan rsync ke direktori aktif mudah dipahami. Namun, ada beberapa hal yang perlu dipahami sebelum menggunakannya untuk sistem bisnis.</p><ul><li><strong>Gunakan HTTPS</strong> untuk domain publik dan kelola pembaruan sertifikat.</li><li><strong>Lindungi branch </strong><strong>main</strong> dengan pull request, review, dan status check. Bila perlu, gunakan GitHub Environment dengan approval manual sebelum production.</li><li><strong>Pin third-party GitHub Actions ke full commit SHA</strong> setelah memverifikasi rilis yang digunakan; major-version tag dipakai di tutorial ini demi kemudahan pembelajaran.</li><li><strong>Pisahkan konfigurasi dari source code.</strong> Jangan commit password database, API key, token, private key, atau .env berisi rahasia. Berikan permission file konfigurasi sensitif sekecil mungkin.</li><li><strong>Lakukan backup</strong> untuk database dan file pengguna. Jangan menempatkan data persisten di dalam folder yang disinkronkan dengan rsync --delete.</li><li><strong>Pikirkan rollback.</strong> Cara di tutorial ini memperbarui direktori aktif. Untuk aplikasi penting, gunakan direktori release berbasis commit/build ID, health check sebelum mengalihkan symlink, dan prosedur rollback ke release sebelumnya.</li><li><strong>Migrasi database perlu strategi tersendiri.</strong> Pastikan migrasi kompatibel dengan versi aplikasi lama/baru serta memiliki backup sebelum perubahan yang berisiko.</li><li><strong>Gunakan staging</strong> jika aplikasi punya pengguna sungguhan; validasi di staging sebelum production.</li><li><strong>Perbarui OS dan dependency</strong> secara terencana, serta pantau log dan penggunaan resource.</li><li><strong>Jangan membuka port Node.js ke publik</strong> bila Nginx adalah reverse proxy. Pada contoh ini Node.js hanya bind ke 127.0.0.1.</li></ul><h3>Apa yang berubah untuk framework lain?</h3><ul><li><strong>Express / NestJS / backend Node.js:</strong> sesuaikan perintah test, build, entry point, port, dan dependency sesuai package.json. NestJS atau TypeScript biasanya memerlukan npm run build, lalu PM2 menjalankan output build.</li><li><strong>React + Vite:</strong> umumnya build di runner dengan npm ci, npm test, npm run build, lalu upload folder dist/ ke folder static web Nginx. Anda tidak membutuhkan PM2 untuk file frontend statis.</li><li><strong>Next.js:</strong> deployment bergantung pada apakah aplikasi memakai server runtime, static export, atau container. Konfigurasikan build/start dan variable environment sesuai jenis deployment.</li><li><strong>Laravel / PHP:</strong> gunakan PHP-FPM, Composer, migrasi database, dan langkah deployment Laravel yang sesuai; Node.js/PM2 di tutorial ini bukan pengganti runtime PHP.</li><li><strong>Docker:</strong> pipeline dapat membangun image, mem-push image ke registry, lalu VPS melakukan pull dan mengganti container. Itu merupakan pola deployment lain dan tidak dibahas detail di tutorial ini.</li></ul><h3>Ringkasan untuk slide</h3><ul><li><strong>SDLC</strong> adalah keseluruhan siklus pengembangan software.</li><li><strong>CI (Continuous Integration)</strong> mengintegrasikan perubahan dan menjalankan pemeriksaan otomatis seperti test.</li><li><strong>CD (Continuous Delivery/Deployment)</strong> mengirim aplikasi melalui proses rilis yang terkontrol atau otomatis.</li><li>Dalam praktik ini, GitHub Actions menjalankan npm ci dan npm test sebelum mengirim kode ke VPS.</li><li>SSH key mengautentikasi workflow; known_hosts memvalidasi identitas server.</li><li>rsync mengirim file, PM2 mengelola proses Node.js, dan Nginx menjadi reverse proxy.</li><li>Health check membantu mendeteksi deployment yang tidak berhasil.</li><li>Deployment otomatis tetap perlu secrets management, branch protection, monitoring, backup, dan rencana rollback.</li></ul><h3>Checklist akhir praktikum</h3><ul><li>[ ] npm test berhasil di komputer lokal.</li><li>[ ] package-lock.json ada di repository.</li><li>[ ] User deploy dibuat dan tidak memerlukan akses sudo untuk deployment biasa.</li><li>[ ] Node.js, npm, PM2, Nginx, dan rsync tersedia di VPS.</li><li>[ ] SSH key berhasil dipakai untuk login sebagai deploy.</li><li>[ ] Fingerprint host sudah diverifikasi dan VPS_KNOWN_HOSTS disimpan sebagai secret.</li><li>[ ] Semua GitHub Secrets sudah terpasang dengan benar.</li><li>[ ] Workflow berhasil berjalan sampai health check.</li><li>[ ] http://VPS_IP/health atau endpoint domain mengembalikan HTTP 200.</li><li>[ ] PM2 startup dikonfigurasi untuk pemulihan setelah reboot.</li><li>[ ] Firewall tidak mengekspos port aplikasi 3000 ke publik.</li></ul><h3>Referensi resmi</h3><ul><li><a href="https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax">GitHub Actions — Workflow syntax</a></li><li><a href="https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions">GitHub Actions — Using secrets</a></li><li><a href="https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions">GitHub Actions — Security hardening</a></li><li><a href="https://github.com/actions/checkout">actions/checkout</a></li><li><a href="https://github.com/actions/setup-node">actions/setup-node</a></li><li><a href="https://nodejs.org/en/download">Node.js downloads and release status</a></li><li><a href="https://ubuntu.com/server/docs/openssh-server/">Ubuntu Server — OpenSSH</a></li><li><a href="https://ubuntu.com/server/docs/firewalls/">Ubuntu Server — Firewall / UFW</a></li><li><a href="https://doc.pm2.io/en/runtime/quick-start/">PM2 — Quick Start</a></li><li><a href="https://pm2.io/docs/runtime/reference/ecosystem-file/">PM2 — Ecosystem file</a></li><li><a href="https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy">NGINX — Reverse proxy</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9698c9dae0ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Membangun Chatbot Tanpa Koding Dengan Custom LLM + RAG]]></title>
            <link>https://medium.com/@raihannismara/membangun-chatbot-tanpa-koding-dengan-custom-llm-rag-ba10877489e3?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba10877489e3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chabot]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Sat, 10 Oct 2026 03:18:54 GMT</pubDate>
            <atom:updated>2026-10-11T10:11:30.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Setelah sebelumnya kita membuat <strong>RAG di n8n</strong>, sekarang kita lanjutkan menjadi aplikasi nyata: <strong>custom chatbot dengan frontend React dan n8n sebagai backend AI</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ncej2zdM8Q8uR7x3" /><figcaption>Photo by <a href="https://unsplash.com/@akurakuu?utm_source=medium&amp;utm_medium=referral">kuu akura</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Arsitektur yang akan diterapkan kurang lebih seperti ini</p><pre>┌──────────────────────┐<br>│    React Frontend    │<br>│                      │<br>│ User: Apa itu RAG?   │<br>└──────────┬───────────┘<br>           │<br>           │ POST /webhook/chat<br>           ▼<br>┌──────────────────────┐<br>│         n8n          │<br>│                      │<br>│ Webhook              │<br>│    ↓                 │<br>│ AI Agent             │<br>│    ↓                 │<br>│ Vector Store / RAG   │<br>│    ↓                 │<br>│ LLM                  │<br>└──────────┬───────────┘<br>           │<br>           │ JSON<br>           ▼<br>┌──────────────────────┐<br>│    React Frontend    │<br>│                      │<br>│ AI: RAG adalah...    │<br>└──────────────────────┘</pre><p>Jadi pembagiannya sederhana:</p><p><strong>React</strong></p><ul><li>tampilan chatbot</li><li>input user</li><li>chat history</li><li>loading state</li></ul><p><strong>n8n</strong></p><ul><li>API/backend</li><li>AI Agent</li><li>RAG</li><li>LLM</li><li>database/vector database</li><li>automation</li></ul><h3>1. Buat Workflow n8n</h3><h4>Menambahkan Node Webhook</h4><p>Dapat menggunakan Workflow baru atau yang lama tambahkan trigger webhook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*fwGA63KfyyO9gVT6yII3Qg.png" /></figure><p>Masuk pada bagian detailnya lalu tambahkan basic auth agar webhook lebih aman tidak dapat digunakan sembarangan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*MJzU4USmb1Kwy383zo5SBQ.png" /></figure><p>Bagian credential buat akun baru sesuaikan dengan kebutuhan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*wY7cYh5zUfs5YUIEwWg2-g.png" /></figure><p>Selanjutnya kembali pada detail node webhook tadi bagian respond ubah menjadi seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*jw2nHDOaV59Szt3lsgV6Gg.png" /></figure><h4>Menambahkan Node AI Agent</h4><p>Selanjutnya penambahan node AI Agent dapat menggunakan node baru atau yang sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*0KgxkEtcs7KsQ-XAKkbF3Q.png" /></figure><p>Lalu tambahkan detailnya seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*-1Re113tH03xZZOUoIakzw.png" /></figure><p>Setelah itu tambah model, memory dan tool seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*bC7pvyfGF4uNZBGv-HHk7w.png" /></figure><p>Pada bagian Supabase vector tool tambahakn embedding model dengan model yang dilatih RAG sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*YXcRzNkcaF6gS2KFpeCMmA.png" /></figure><p>Selanjutnya bagian respond tambahkan loading dan custom kode javascript seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*DxWZ2mYLSGzJfV7zEF1_pQ.png" /></figure><p>Tambahakn waktu tunggu respon AI 1–3 detik, untuk kode salin seperti ini</p><pre>const output = $(&#39;AI Agent&#39;).first().json.output<br><br>return [<br>  {<br>    json: JSON.parse(output),<br>  },<br>];</pre><p>Karena hasil sebelumnya akan selalu satu objek bertumpuk seperti ini</p><pre>[<br>  {<br>    &quot;output&quot;: &quot;{\n  \&quot;success\&quot;: true,\n  \&quot;conversationId\&quot;: \&quot;59443a7f-9b83-471e-8fa2-5817aeb0d205\&quot;,\n  \&quot;message\&quot;: {\n    \&quot;id\&quot;: \&quot;msg_002\&quot;,\n    \&quot;role\&quot;: \&quot;assistant\&quot;,\n    \&quot;content\&quot;: \&quot;Karya berjudul \\\&quot;Kamus Bahasa dan Seni Budaya Sunda Kuno Abad XI sampai dengan XX Masehi\\\&quot; disusun oleh **Elis Suryani NS** dari Fakultas Sastra Universitas Padjadjaran. Penelitian ini mengungkapkan istilah-istilah dari tujuh aspek budaya Sunda (sistem religi, teknologi, kemasyarakatan, ekonomi, pendidikan, bahasa, dan kesenian) yang bersumber dari naskah dan prasasti Sunda kuno.\&quot;\n  },\n  \&quot;metadata\&quot;: {\n    \&quot;model\&quot;: \&quot;gpt-4o\&quot;,\n    \&quot;tokens\&quot;: 620,\n    \&quot;duration\&quot;: 2200\n  }\n}&quot;<br>  }<br>]</pre><p>Dari kostum kode diatas akan berubah menjadi lebih rapi</p><pre>[<br>  {<br>    &quot;success&quot;: true,<br>    &quot;conversationId&quot;: &quot;59443a7f-9b83-471e-8fa2-5817aeb0d205&quot;,<br>    &quot;message&quot;: {<br>      &quot;id&quot;: &quot;msg_002&quot;,<br>      &quot;role&quot;: &quot;assistant&quot;,<br>      &quot;content&quot;: &quot;Karya berjudul \&quot;Kamus Bahasa dan Seni Budaya Sunda Kuno Abad XI sampai dengan XX Masehi\&quot; disusun oleh **Elis Suryani NS** dari Fakultas Sastra Universitas Padjadjaran. Penelitian ini mengungkapkan istilah-istilah dari tujuh aspek budaya Sunda (sistem religi, teknologi, kemasyarakatan, ekonomi, pendidikan, bahasa, dan kesenian) yang bersumber dari naskah dan prasasti Sunda kuno.&quot;<br>    },<br>    &quot;metadata&quot;: {<br>      &quot;model&quot;: &quot;gpt-4o&quot;,<br>      &quot;tokens&quot;: 620,<br>      &quot;duration&quot;: 2200<br>    }<br>  }<br>]</pre><p>Node terakhir tambahkan respond to webhook seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*xl904sN2hi5-H5ABORgHkQ.png" /></figure><h3>2. Testing Webhook Dengan Postman</h3><p>Postman ialah testing HTTP/API yang memudahkan melihat payload tanpa membutuhkan UI dari frontend. Langsung saja download postman <a href="https://www.postman.com/">disini</a></p><p>Salin webhook test url ke postman dengan basic auth seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*C3KGYuC0sPftGoXUavbA4A.png" /></figure><p>Lalu bagian body tambahkan chat yang akan ditanyakan bagian conversationid, userid, timestamp tambahakn sesuai format masing-masing untuk test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*3RO7rz_eGgq0p2O2IhGwRA.png" /></figure><p>Nyalakan workflow execute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*vIp-IwCbrUUtD2hFrE3KYw.png" /></figure><p>Jika berhasil akan terlihat respon seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*dfZY1BKdRYW5Bio-tZJrHw.png" /></figure><blockquote>Jika hasil chat model masih belum sesuai jawaban dari model RAG yang dilatih sebelumnya, coba ubah model AI agent / embedding model terkadang bagian tersebut yang membuat kekeliruan.</blockquote><h3>3. Membangun User Interface — Frontend</h3><p>Nah jika sistem backend selesai (webhook) selanjutnya kita akan membuat tampilan antarmukanya agar dapat input chat tanpa harus dengan tool testing seperti postman tadi.</p><p>Pada pembuatan UI ini kita akan dibantu oleh tool vibe coding lainnya lovable.dev daftar terlebih dahulu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/0*dUQpuR2ZXXZUZWM9.png" /></figure><p>Setelah berhasil daftar, kita cukup menuliskan prompt yang menjelaskan tampilan chatbot sekaligus cara aplikasi berkomunikasi dengan webhook n8n. Lovable akan membuatkan project React lengkap dengan Tailwind tanpa harus menulis kode satu baris pun.</p><p>Buka dashboard Lovable lalu tuliskan prompt seperti ini, jangan lupa ganti URL webhook dengan milik kalian sendiri</p><pre>Buatkan aplikasi chatbot menggunakan React dan Tailwind CSS dengan tampilan mirip ChatGPT.<br><br>Tampilan:<br>- Area chat history di tengah, pesan user di kanan dan pesan AI di kiri<br>- Input teks dan tombol kirim di bagian bawah<br>- Tampilkan loading indicator (titik-titik mengetik) saat menunggu respon AI<br>- Render balasan AI sebagai markdown<br><br>Koneksi ke backend:<br>- Setiap pesan dikirim dengan method POST ke URL webhook n8n berikut: https://URL-N8N-KALIAN/webhook/chat<br>- Gunakan Basic Auth dengan username dan password dari environment variable<br>- Body request: { &quot;message&quot;: string, &quot;conversationId&quot;: string, &quot;userId&quot;: string, &quot;timestamp&quot;: string }<br>- Response: { &quot;success&quot;: boolean, &quot;conversationId&quot;: string, &quot;message&quot;: { &quot;id&quot;: string, &quot;role&quot;: string, &quot;content&quot;: string }, &quot;metadata&quot;: object }<br>- Tampilkan message.content sebagai balasan AI<br>- Simpan conversationId agar percakapan tetap berlanjut<br>- Jika request gagal, tampilkan pesan error yang ramah</pre><p>Tunggu beberapa saat sampai Lovable selesai membuat aplikasinya. Di sebelah kiri kita dapat melihat proses yang dikerjakan AI, sedangkan di sebelah kanan muncul preview tampilan chatbot yang sudah jadi.</p><p>Jika ada bagian tampilan yang kurang sesuai, cukup minta perubahan lewat chat Lovable, misalnya “ubah warna bubble chat user menjadi ungu” atau “tambahkan tombol untuk memulai percakapan baru”.</p><h4>Mengatasi Error CORS</h4><p>Saat pertama kali mencoba mengirim chat dari preview Lovable, biasanya akan muncul error CORS di console browser. Ini terjadi karena browser memblokir request dari domain Lovable ke domain n8n kita.</p><p>Untuk mengatasinya, kembali ke node Webhook di n8n lalu buka bagian Options, tambahkan Allowed Origins (CORS) dan isi dengan domain aplikasi Lovable kalian. Untuk tahap testing bisa diisi dengan * terlebih dahulu, namun sebaiknya diganti dengan domain asli sebelum aplikasi dipublikasikan.</p><h3>4. Menghubungkan dan Testing Chatbot</h3><p>Pastikan workflow n8n sudah dalam keadaan aktif (Active), lalu ganti URL webhook di aplikasi dari test URL menjadi production URL. Test URL hanya berjalan ketika kita menekan execute workflow, sedangkan production URL akan selalu siap menerima request selama workflow aktif.</p><p>Sekarang coba ketik pertanyaan pada input chat. Jika semuanya berjalan lancar, loading indicator akan muncul beberapa detik lalu digantikan dengan jawaban dari AI Agent yang sudah mengambil konteks dari vector store RAG kita.</p><p>Coba juga ajukan pertanyaan lanjutan untuk memastikan memory berjalan dengan baik. Karena conversationId selalu dikirim ke n8n, AI Agent akan mengingat konteks percakapan sebelumnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OU5iIcIQNeUlfHJ-tzwF-A.png" /><figcaption>final output chatbot</figcaption></figure><h4>Catatan Keamanan</h4><p>Perlu diingat, menyimpan username dan password Basic Auth di frontend berarti siapa pun yang membuka source code aplikasi tetap bisa melihatnya. Untuk project belajar atau demo internal hal ini masih aman, tetapi untuk aplikasi production sebaiknya tambahkan lapisan backend atau proxy (misalnya Supabase Edge Function) sehingga kredensial webhook tidak terekspos di browser.</p><h3>5. Publish Aplikasi</h3><p>Jika semua sudah sesuai, klik tombol Publish di pojok kanan atas Lovable. Aplikasi chatbot kita akan langsung mendapatkan domain publik dan siap dibagikan ke orang lain.</p><h3>Penutup</h3><p>Sampai di sini kita sudah berhasil membangun chatbot dengan custom LLM + RAG tanpa menulis kode secara manual. n8n berperan sebagai otak di belakang layar yang mengatur AI Agent, memory, dan vector store, sementara Lovable membantu kita membuat tampilan React yang rapi hanya dari sebuah prompt.</p><p>Ke depannya chatbot ini masih bisa dikembangkan lagi, misalnya menambahkan login user, menyimpan riwayat chat ke database, atau fitur upload dokumen agar knowledge base RAG bisa diperbarui langsung dari aplikasi. Selamat mencoba dan semoga bermanfaat!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba10877489e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Melatih Model Besar Dengan Teknik RAG Pada n8n]]></title>
            <link>https://medium.com/@raihannismara/melatih-model-besar-dengan-teknik-rag-pada-n8n-be25f1a990b9?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/be25f1a990b9</guid>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Fri, 02 Oct 2026 11:01:47 GMT</pubDate>
            <atom:updated>2026-10-02T11:01:47.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W4vdeOn9qXfn_8Hb" /><figcaption>Photo by <a href="https://unsplash.com/@roadtripwithraj?utm_source=medium&amp;utm_medium=referral">Road Trip with Raj</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Tutorial ini ditujukan untuk pemula yang ingin membuat chatbot AI yang bisa menjawab berdasarkan dokumen sendiri menggunakan <strong>Retrieval-Augmented Generation (RAG)</strong>. Kita akan menggunakan:</p><ul><li><strong>n8n</strong> sebagai orchestration workflow</li><li><strong>gemini / gemma </strong>sebagai model LLM</li><li><strong>Supabase</strong> sebagai vector database</li></ul><h3>Apa itu RAG?</h3><p><strong>RAG (Retrieval-Augmented Generation)</strong> adalah teknik dalam kecerdasan buatan (AI) yang menggabungkan kemampuan pencarian data eksternal dengan model bahasa besar (LLM) untuk menghasilkan jawaban yang lebih akurat dan faktual.</p><p>Illustrasi</p><pre>// tanpa RAG<br><br>User<br>  ↓<br>LLM<br>  ↓<br>Jawaban berdasarkan data training lama</pre><pre>// dengan RAG<br><br>User<br>  ↓<br>Cari dokumen relevan<br>  ↓<br>Kirim dokumen ke LLM<br>  ↓<br>LLM menjawab berdasarkan dokumen</pre><h3>Step 1 — Membuat Workflow Baru</h3><p>Pastikan <a href="https://n8n.io/">n8n</a> telah terpasang di vps/laptop sendiri. Pergi ke menu personal klik <em>new workflow</em> beri nama ‘RAG Simple’ atau dapat disesuaikan.</p><p>Bagian node pertama, gunakan trigger <em>on click manual</em> terlebih dulu, lalu tambah node berikut nya yaitu <em>Drive &gt; Download file</em></p><p>Pastikan node Drive dari Google telah terpasang sebelumnya.<br>Pada bagian file pilih sumber yang ingin jadikan sebagai pengetahuan baru pada modelnya nanti disini akan menggunakan file <em>.pdf</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*YB6D8wHUb5yE_dwSQkN1Qg.png" /></figure><p>Kembali ke canvas workflow sekarang akan terlihat kurang lebih seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*kNWfYUP53RiEVgP7F99_2Q.png" /></figure><h3>Step 2 — Menghubungkan Supabase</h3><p>Untuk vector db teknologi yang akan digunakan ialah Supabase, buat project dan table baru. Jika belum memiliki akun daftar terlebih dulu <a href="http://supabase.com/">disini</a></p><p>Buat project baru isi hingga lengkap, tunggu hingga selesai jika berhasil status berubah warna hijau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*zo0OucLfYWfosnbS4y_7wg.png" /></figure><p>Kembali ke n8n tambahkan node baru yaitu <em>Supabase &gt; Vector Database</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*FU7l_LBOWxMToFfg-F9A9A.png" /></figure><p>Jika belum terkonek dengan Supabase tambah new credential salin <em>host</em> dan <em>api secret</em> dari Supabase</p><p>Jika secret key masih kosong, buat terlebih dahulu seperti ini.<br>Masuk ke <em>Project &gt; Settings &gt; API Keys</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*QMbm2S5oeVdF-0MQ36Ml1Q.png" /></figure><p>Untuk host url dapatkan di halaman Project Overview</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*YcEas1btKriljqKD41XMaw.png" /></figure><p>Salin keduanya secret keys &amp; host url di n8n tadi seperti berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*HQqdUCKHEnqrFOf3nxKuVg.png" /></figure><p>Sekarang membuat table document di Supabase untuk menampung hasil RAG dokumen yang kita submit salin kode untuk membuat table <a href="https://supabase.com/docs/guides/ai/langchain?queryGroups=database-method&amp;database-method=sql">disini</a></p><p>Masuk ke menu SQL Editor lalu jalankan hasil kode yang disalin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1UsvPxSYVkuU5XoDriQ5A.png" /></figure><p>Perlu diperhatikan bagian disini setiap provider memiliki berbeda-beda size</p><pre>embedding extensions.vector(1536) <br>-- 1536 works for OpenAI embeddings, change if needed (gemini 3072)</pre><p>Jika berhasil document akan terlihat pada table di Supabase seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*odK--yILvAi5zFnl1EnvJg.png" /></figure><p>Langkah selanjutnya kembali pada n8n buka node Supabase yang telah ditambahkan sebelumnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MtJCxt5RZCQ_MIWTTvKgJQ.png" /></figure><p>Tutup node kemudian tambahkan pada bagian document tool seperti berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUo6O1yOrqXf_duhGGityw.png" /></figure><p>Pilih bagian default data loader lalu isi seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kO0uBaYabYhkQfL5pvSkmw.png" /></figure><p>Bagian mime type dapat langsung dipilih PDF</p><h3>Step 3 — Menentukan Model Embedding</h3><p>Kembali pada node Supabase pilih embedding model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*QBxQRRcjP-rdiI6uKtNi1Q.png" /></figure><p>Contoh kali akan menggunakan model embedding Gemini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*-KgAxf3rpwqyv2MAKhsofA.png" /></figure><p>Jika credential belum dibuat pergi ke sini <a href="https://aistudio.google.com/api-keys">https://aistudio.google.com/api-keys</a></p><p>Selanjutnya setelah semua selesai jalankan workflow terlebih dulu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*cJLhGTbhBuOSop9hlMuG8g.png" /></figure><p>Ketika workflow berubah hijau semua node berhasil dijalankan dan documents table yang dibuat sebelumnya akan terisi oleh <em>chunks </em>data dari PDF seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*A_0DdmejvhLlPiK3AnY90A.png" /></figure><h3>Step 4 — Membuat Chat Workflow</h3><p>Pada bagian ini saatnya pengujian untuk melihat bagaimana hasil pelatihan model sebelumnya.</p><p>Tambahkan <em>trigger workflow </em>baru, Chat Trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*V6Y6gO3t-VwbmoHGRm92Yg.png" /></figure><p>Kemudian tambahkan juga AI Agent node</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*xOOFOETOGKEX5t40MdOqUQ.png" /></figure><p>Pastikan detail AI Agent terlihat seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ycGHv8-zvoKQfjhTueGGPw.png" /></figure><p>Buka node AI Agent tambahkan Chat Model pilih model yang selaras dengan embedding sebelumnya misal OpenAI/OpenAI atau Gemini/Gemini tidak disarankan mencampurkan model seperti Gemini/OpenAI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*7uFadCLMIuYLcraEsLIWJw.png" /></figure><p>Tutup detail node tambahkan Tool pada AI Agent pilih Supabase Vector Store</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*mU9A9G6hbr09dwRecYEA2g.png" /></figure><p>Isikan detail sesuai kebutuhan yang diperlukan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*FOJfm4zhzfUi0OuTfOzFlg.png" /></figure><p>Kembali ke canvas bagian Embedding model tool pada node Supabase tarik pointer ujung lalu hubungkan ke Embedding model yang dibuat sebelumnya seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*AFa6SB5qxXIZSFoNUqr6BA.png" /></figure><h3>Step 5 — Testing Time</h3><p>Selanjutnya open chat modal lalu berikan pertanyaan yang merujuk ke dokumen sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*7MhzpelV8mBakZb3exBCTQ.png" /></figure><p>Bertanya mengenai aturan main golf, jika berhasil model akan mengembalikan konteks tulisan yang telah di <em>chunk</em> sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*OYda40FoZ6z9tt7zH7Qmqw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be25f1a990b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Menggunakan N8N Pada VPS Ubuntu lengkap dengan domain, npm & NGINX]]></title>
            <link>https://medium.com/@raihannismara/menggunakan-n8n-pada-vps-ubuntu-lengkap-dengan-domain-npm-nginx-15550bf56343?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15550bf56343</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[writing-tips]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 10:24:37 GMT</pubDate>
            <atom:updated>2026-09-23T10:24:37.581Z</atom:updated>
            <content:encoded><![CDATA[<p>Saat membuat aplikasi AI, banyak developer langsung menaruh seluruh logika chatbot di backend Express atau NestJS. Padahal ada pendekatan yang lebih cepat dan fleksibel: menggunakan <strong>n8n sebagai backend orchestration</strong>, dan <strong>React Router sebagai frontend chatbot</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l8W8IoLd3xjkat00" /><figcaption>Photo by <a href="https://unsplash.com/@michaelfousert?utm_source=medium&amp;utm_medium=referral">Michael Fousert</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Mengapa Menggunakan n8n Sebagai Backend?</h3><p>Biasanya backend chatbot bertugas:</p><ul><li>Menerima pesan user</li><li>Mengirim prompt ke LLM</li><li>Menyimpan history</li><li>Memanggil API eksternal</li><li>Mengembalikan respons</li></ul><p>Semua pekerjaan tersebut sebenarnya dapat dilakukan oleh n8n tanpa menulis banyak kode.</p><p>Rekomendasi spesifikasi mesin yang digunakan</p><p>4 CPU</p><p>8 GB RAM</p><p>50 GB SSD</p><h4>1. Install Node.js LTS</h4><p>Update server terlebih dahulu</p><pre>sudo apt update<br>sudo apt upgrade -y</pre><p>Install Node.js 22 LTS menggunakan NodeSource:</p><pre>curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -<br>sudo apt install -y nodejs</pre><p>Verifikasi instalasi dengan perintah</p><pre>node -v<br>npm -v</pre><p>Contoh: <br>v22.x.x<br>10.x.x</p><h4>2. Install n8n Global</h4><p>Pasang n8n secara global</p><pre>sudo npm install -g n8n</pre><p>Cek terlebih dahulu, nanti muncul versi yang berhasil dipasang</p><pre>n8n - version</pre><h4>3. Install NGINX</h4><p>Karena nantinya akan dihubungkan dengan custom domain untuk akses n8n, pasang nginx terlebih dahulu dengan perintah berikut</p><pre>sudo apt install nginx -y<br><br>nginx -t</pre><p>Buat konfigurasi vhost (pengaturan web server)</p><pre>sudo nano /etc/nginx/sites-available/n8n</pre><p>Salin dokumen dibawah</p><pre>map $http_upgrade $connection_upgrade {<br>    default upgrade;<br>   &#39;&#39;      close;<br>}<br><br>server {<br>    server_name custom.domain.com;<br><br>    # Will be replaced by Certbot later<br>    location / {<br>        proxy_pass http://127.0.0.1:5678; ## n8n default url<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection $connection_upgrade;<br>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_buffering off;<br>        proxy_cache off;<br>        chunked_transfer_encoding off;<br>    }<br>}</pre><p>Aktikan vhost dengan perintah</p><pre>sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/<br>sudo nginx -t<br>sudo systemctl restart nginx</pre><p>Jika gagal akan muncul failed nginx xxx</p><h4>4. Konek dengan domain</h4><p>Sekarang masuk ke penyedia domain buka bagian <strong>Domain &gt; DNS Management</strong></p><p>Add record tambahkan type A</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Pt9j7WS3l8yAyIZ2dC5mPA.png" /></figure><ul><li>host name = nama domain</li><li>record type = a</li><li>address/value = alamat ip server</li></ul><p>Setelah berhasil tunggu untuk propagation terubah antara 15 menit — 1 hari</p><h4>5. Konfigurasi n8n live</h4><p>Jika domain berhasil terkoneksi, coba tes dengan perintah memasang SSL untuk keamanan domain</p><pre>sudo apt install certbot python3-certbot-nginx -y</pre><p>Generate SSL untuk domain yang terkonek</p><pre>sudo certbot --nginx -d custom.domain.com</pre><p>Jika berhasil domainnya akan terenkripsi secara aman diawali <a href="https://n8n.domain.com/">https://</a></p><p>Selanjutnya atur n8n callback kalian dengan domain baru yang terhubung caranya</p><pre>export N8N_WEBHOOK_URL=https://custom.domain.com</pre><p>Setelah oke, jalankan</p><pre>n8n start</pre><p>Jika berhasil akan terlihat seperti ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/0*riZwOawWEkbcaNm3" /></figure><p>Saat diakses akan terlihat tampilan setup pertama kali dan lengkapi data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*Gsk-UAwDRLkDb87M.png" /></figure><h4>6. Pemasangan PM2</h4><p>PM2 merupakan tool yang berguna menjalankan perintah-perintah node, javacript di dalam server, agar nantinya tidak membutuhkan perintah sesuatu secara manual.</p><pre>sudo npm install -g pm2</pre><p>Matikan untuk sementara n8n yang berjalan</p><p>Lalu jalankan perintah n8n di dalam PM2</p><pre>pm2 start n8n - name n8n</pre><p>Agar tetap tersimpan sewaktu-waktu server mati atau harus restart tidak perlu konfigurasi ulang dengan perintah</p><pre>pm2 startup<br><br>pm2 save</pre><p>Bagian paling seru adalah mencoba automasi n8n untuk pertama kalinya.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15550bf56343" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Menggunakan Model Hugging Face via Ollama]]></title>
            <link>https://medium.com/@raihannismara/menggunakan-model-hugging-face-via-ollama-2a4d418dc5af?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a4d418dc5af</guid>
            <category><![CDATA[ollama]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Sun, 20 Sep 2026 07:56:47 GMT</pubDate>
            <atom:updated>2026-09-20T07:56:47.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VHj4aq8xOTC4JsPM" /><figcaption>Photo by <a href="https://unsplash.com/@chaiclikz?utm_source=medium&amp;utm_medium=referral">chaitanya pillala</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Model bahasa kecil semakin menarik untuk dijalankan secara lokal. Dalam tutorial ini, kita akan menggunakan <strong>Qwen3–0.6B-GGUF</strong> dari Hugging Face dan menjalankannya menggunakan <strong>Ollama</strong> tanpa perlu GPU kelas tinggi. Cocok untuk eksperimen AI lokal, chatbot sederhana, maupun pembelajaran LLM.</p><h3>Mengapa Menggunakan Qwen3–0.6B?</h3><p><strong>Qwen3–0.6B</strong> merupakan model ringan dari keluarga Qwen yang dirancang agar dapat berjalan pada perangkat dengan sumber daya terbatas. Format <strong>GGUF</strong> membuat model ini kompatibel dengan berbagai runtime lokal seperti Ollama dan llama.cpp.</p><p>Beberapa keunggulannya:</p><ul><li>Ukuran model relatif kecil</li><li>Konsumsi RAM lebih rendah</li><li>Cocok untuk laptop dan mini PC</li><li>Mendukung penggunaan offline</li><li>Proses deployment sederhana</li></ul><p>Model yang digunakan dalam tutorial ini tersedia di Hugging Face:</p><p>👉 <a href="https://huggingface.co/Qwen/Qwen3-0.6B-GGUF">Qwen3–0.6B-GGUF</a></p><h3>Prasyarat</h3><p>Sebelum memulai, pastikan sudah terpasang:</p><ul><li>Ollama versi terbaru</li><li>Git (opsional)</li><li>Hugging Face CLI (opsional)</li></ul><p>Jika sudah terpasang jalankan perintah berikut</p><pre>ollama pull --insecure hf.co/Qwen/Qwen3-0.6B-GGUF:Q8_0</pre><p>Parameter <em>insecure</em> digunakan jika terjadi <strong>error head blocked redirect different host</strong></p><p>Jangan khawatir, tetap aman. Pastikan pembuat model dari organisasi atau user terverifikasi.</p><p>Jalankan model</p><pre>ollama list</pre><pre>ollama run hf.co/Qwen/Qwen3-0.6B-GGUF:Q8_0</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a4d418dc5af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loseless AI Token Consumption Techniques I Used for Web App]]></title>
            <link>https://blog.stackademic.com/loseless-ai-token-consumption-techniques-i-used-for-web-app-4f93e59aecb2?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f93e59aecb2</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Tue, 23 Jun 2026 13:55:18 GMT</pubDate>
            <atom:updated>2026-06-25T12:22:13.956Z</atom:updated>
            <content:encoded><![CDATA[<p>A month ago, a client asked me to build their own web-based chatbot AI app, and I learned something important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wV5rLCLFzrs-oJE4" /><figcaption>Photo by <a href="https://unsplash.com/@federize?utm_source=medium&amp;utm_medium=referral">Federico Beccari</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There’s a quiet tax that every AI-powered web app pays: <strong>tokens</strong>. Every prompt, every system instruction, every conversation history you feed into the model costs you — in latency, in dollars, and in rate limits. When I was building a React TypeScript web app that made heavy use of Claude’s API, I realized pretty early that I was being <em>careless</em> with this resource.</p><p>What followed was a focused optimization sprint. I landed on three techniques that meaningfully reduced my token usage without losing a single bit of response quality. I call this approach <strong>Lossless AI Token Consumption</strong> — trimming the fat, not the muscle.</p><p>Here’s exactly what I did.</p><h3>1. Defluffing: Stop Sending Noise to the Model</h3><p>The first and most impactful change was what I call <strong>defluffing</strong> — stripping unnecessary verbosity from every prompt before it hits the API.</p><p>Before defluffing, my system prompts and user messages looked like this:</p><pre>&quot;Please kindly help me by providing a detailed and thorough explanation <br>about the following topic that the user is curious about and would like <br>to understand better. The user is asking: what is React Server Components?&quot;</pre><p>That’s 38 words to say: <em>“Explain React Server Components.”</em></p><p>I built a small defluffer utility in TypeScript that runs every prompt through a pipeline before dispatch:</p><pre>// utils/defluffer.ts<br>const FILLER_PATTERNS: RegExp[] = [<br>  /\bplease\s+kindly\b/gi,<br>  /\bcan you\s+please\b/gi,<br>  /\bI was wondering if\b/gi,<br>  /\bif you don&#39;t mind\b/gi,<br>  /\bthank you in advance\b/gi,<br>  /\bas an AI language model,?\s*/gi,<br>  /\bcertainly[!,.]?\s*/gi,<br>  /\bof course[!,.]?\s*/gi,<br>  /\bsure[!,.]?\s+I(&#39;d| will| can)\s+/gi,<br>];<br>const REDUNDANT_PREAMBLES: RegExp[] = [<br>  /^(Hello|Hi|Hey)[,!]?\s+/i,<br>  /^Great question[!.]?\s*/i,<br>  /^That&#39;s (a great|an interesting|a good)\s+(question|point)[!.]?\s*/i,<br>];<br>export function defluff(text: string): string {<br>  let result = text.trim();<br>  for (const pattern of FILLER_PATTERNS) {<br>    result = result.replace(pattern, &#39; &#39;);<br>  }<br>  for (const pattern of REDUNDANT_PREAMBLES) {<br>    result = result.replace(pattern, &#39;&#39;);<br>  }<br>  // Collapse multiple spaces<br>  result = result.replace(/\s{2,}/g, &#39; &#39;).trim();<br>  return result;<br>}const FILLER_PATTERNS: RegExp[] = [<br>  /\bplease\s+kindly\b/gi,<br>  /\bcan you\s+please\b/gi,<br>  /\bI was wondering if\b/gi,<br>  /\bif you don&#39;t mind\b/gi,<br>  /\bthank you in advance\b/gi,<br>  /\bas an AI language model,?\s*/gi,<br>  /\bcertainly[!,.]?\s*/gi,<br>  /\bof course[!,.]?\s*/gi,<br>  /\bsure[!,.]?\s+I(&#39;d| will| can)\s+/gi,<br>];<br>const REDUNDANT_PREAMBLES: RegExp[] = [<br>  /^(Hello|Hi|Hey)[,!]?\s+/i,<br>  /^Great question[!.]?\s*/i,<br>  /^That&#39;s (a great|an interesting|a good)\s+(question|point)[!.]?\s*/i,<br>];<br>export function defluff(text: string): string {<br>  let result = text.trim();<br>  for (const pattern of FILLER_PATTERNS) {<br>    result = result.replace(pattern, &#39; &#39;);<br>  }<br>  for (const pattern of REDUNDANT_PREAMBLES) {<br>    result = result.replace(pattern, &#39;&#39;);<br>  }<br>  // Collapse multiple spaces<br>  result = result.replace(/\s{2,}/g, &#39; &#39;).trim();<br>  return result;<br>}</pre><p>I applied this to <strong>both</strong> directions — cleaning up user inputs before sending them, and optionally post-processing assistant responses before storing them in conversation history (since history gets fed back into subsequent requests).</p><p>typescript</p><pre>// hooks/useChat.ts<br>const sendMessage = async (userInput: string) =&gt; {<br>  const cleanedInput = defluff(userInput);<br>  const response = await callClaudeAPI({<br>    messages: conversationHistory.map(msg =&gt; ({<br>      ...msg,<br>      content: defluff(msg.content), // Clean history too<br>    })),<br>    newMessage: cleanedInput,<br>  });<br>  // ...<br>};</pre><p><strong>Result:</strong> On average, I reduced prompt token count by 12–18% for conversational messages. Not glamorous, but it compounds across thousands of requests.</p><h3>2. cache_control: Making the Model Remember Your System Prompt</h3><p>This one was a game-changer for latency and cost.</p><p>If your app has a long, detailed system prompt — instructions, persona definitions, knowledge base snippets — you’re re-sending that same block of tokens <em>on every single request</em>. That’s expensive. Claude’s API supports a cache_control parameter that lets you <strong>mark parts of your prompt as cacheable</strong>, so the model processes them once and reuses the result.</p><p>Here’s how I structured it in my React TypeScript app:</p><p>typescript</p><pre>// api/claude.ts<br>import Anthropic from &quot;@anthropic-ai/sdk&quot;;<br>const client = new Anthropic();<br>const SYSTEM_PROMPT = `<br>You are a senior full-stack engineer specializing in React and TypeScript.<br>You provide concise, production-ready code examples.<br>You follow clean architecture principles.<br>You prefer composition over inheritance.<br>[... 800 more tokens of detailed instructions ...]<br>`.trim();<br>export async function callClaude(<br>  messages: Anthropic.MessageParam[],<br>  userMessage: string<br>): Promise&lt;string&gt; {<br>  const response = await client.messages.create({<br>    model: &quot;claude-sonnet-4-6&quot;,<br>    max_tokens: 1024,<br>    system: [<br>      {<br>        type: &quot;text&quot;,<br>        text: SYSTEM_PROMPT,<br>        cache_control: { type: &quot;ephemeral&quot; }, // 👈 Cache this block<br>      },<br>    ],<br>    messages: [<br>      ...messages,<br>      { role: &quot;user&quot;, content: userMessage },<br>    ],<br>  });<br>  return response.content<br>    .filter((block) =&gt; block.type === &quot;text&quot;)<br>    .map((block) =&gt; (block as Anthropic.TextBlock).text)<br>    .join(&quot;&quot;);<br>}</pre><p>The ephemeral cache type stores the prompt for <strong>5 minutes</strong>, which covers most active user sessions. For a long system prompt that&#39;s 800+ tokens, this means:</p><ul><li><strong>First request:</strong> Full token processing cost</li><li><strong>Subsequent requests within 5 min:</strong> Cache hit — billed at a fraction of the normal input token price</li></ul><p>You can also apply cache_control to large static knowledge base blocks injected into the prompt:</p><p>typescript</p><pre>const buildMessagesWithKnowledgeBase = (<br>  knowledgeBase: string,<br>  conversationHistory: Anthropic.MessageParam[]<br>): Anthropic.MessageParam[] =&gt; {<br>  return [<br>    {<br>      role: &quot;user&quot;,<br>      content: [<br>        {<br>          type: &quot;text&quot;,<br>          text: `Reference documentation:\n\n${knowledgeBase}`,<br>          cache_control: { type: &quot;ephemeral&quot; }, // Cache the static docs<br>        },<br>        {<br>          type: &quot;text&quot;,<br>          text: conversationHistory[0]?.content as string ?? &quot;&quot;,<br>        },<br>      ],<br>    },<br>    ...conversationHistory.slice(1),<br>  ];<br>};</pre><p><strong>Result:</strong> For users who send multiple messages in a session, cache hits dropped my effective input token cost dramatically on the large system prompt. If you have a 1,000-token system prompt and a user sends 10 messages, you pay for 1,000 tokens once instead of 10,000.</p><h3>3. Citation Mapping for Web Search Requests</h3><p>The third technique applies specifically when your app uses Claude’s web search tool. When the model returns cited responses, each citation is a &lt;cite&gt; block referencing a document and sentence index. The naive approach — storing the <em>full</em> fetched web page content in your conversation history — is catastrophically wasteful.</p><p>Instead, I built a <strong>citation mapper</strong> that extracts and stores only the <em>cited excerpts</em>, not the full documents.</p><p>Here’s the pattern:</p><p>typescript</p><pre>// types/citation.ts<br>export interface CitationMap {<br>  [docIndex: number]: {<br>    url: string;<br>    title: string;<br>    excerpts: {<br>      [sentenceIndex: number]: string;<br>    };<br>  };<br>}</pre><pre>// utils/citationMapper.ts<br>export function buildCitationMap(<br>  searchResults: WebSearchResult[]<br>): CitationMap {<br>  const map: CitationMap = {};<br>  searchResults.forEach((result, docIndex) =&gt; {<br>    // Split content into sentences for granular indexing<br>    const sentences = result.content<br>      .split(/(?&lt;=[.!?])\s+/)<br>      .filter((s) =&gt; s.trim().length &gt; 0);<br>    map[docIndex] = {<br>      url: result.url,<br>      title: result.title,<br>      excerpts: Object.fromEntries(<br>        sentences.map((sentence, sentenceIndex) =&gt; [sentenceIndex, sentence])<br>      ),<br>    };<br>  });<br>  return map;<br>}<br>export function extractCitedExcerpts(<br>  responseText: string,<br>  citationMap: CitationMap<br>): string {<br>  // Parse citation indices from response (e.g., [0-2], [1-5:7])<br>  const citationPattern = /\[(\d+)-(\d+)(?::(\d+))?\]/g;<br>  const usedExcerpts = new Set&lt;string&gt;();<br>  let match;<br>  while ((match = citationPattern.exec(responseText)) !== null) {<br>    const docIndex = parseInt(match[1]);<br>    const startSentence = parseInt(match[2]);<br>    const endSentence = match[3] ? parseInt(match[3]) : startSentence;<br>    const doc = citationMap[docIndex];<br>    if (!doc) continue;<br>    for (let i = startSentence; i &lt;= endSentence; i++) {<br>      if (doc.excerpts[i]) {<br>        usedExcerpts.add(`[${docIndex}] ${doc.excerpts[i]}`);<br>      }<br>    }<br>  }<br>  return Array.from(usedExcerpts).join(&quot;\n&quot;);<br>}</pre><p>Then, in the API layer, instead of injecting full page content into subsequent turns, I inject only the cited excerpts:</p><p>typescript</p><pre>// hooks/useWebSearch.ts<br>const handleWebSearchResponse = async (<br>  rawResponse: Anthropic.Message,<br>  searchResults: WebSearchResult[]<br>) =&gt; {<br>  const responseText = rawResponse.content<br>    .filter((b) =&gt; b.type === &quot;text&quot;)<br>    .map((b) =&gt; (b as Anthropic.TextBlock).text)<br>    .join(&quot;&quot;);<br>  const citationMap = buildCitationMap(searchResults);<br>  const citedExcerpts = extractCitedExcerpts(responseText, citationMap);<br>  // Store only cited excerpts in history - NOT full page content<br>  setConversationHistory((prev) =&gt; [<br>    ...prev,<br>    {<br>      role: &quot;assistant&quot;,<br>      content: responseText,<br>    },<br>    {<br>      role: &quot;user&quot;, // Inject as context for next turn<br>      content: `[Referenced excerpts for context]\n${citedExcerpts}`,<br>    },<br>  ]);<br>};</pre><p>A full web page might be 3,000–8,000 tokens. The cited excerpts? Typically 50–300 tokens. For multi-turn conversations involving web search, this is where the real savings compound.</p><h3>Putting It All Together</h3><p>Here’s how these three techniques layer together in the actual request lifecycle:</p><pre>User Input<br>    │<br>    ▼<br>[1. Defluffer] ──► Clean input, strip filler, compress history<br>    │<br>    ▼<br>[2. cache_control] ──► Attach cached system prompt + knowledge base<br>    │<br>    ▼<br>Claude API Request<br>    │<br>    ▼<br>Response + (optional) Search Results<br>    │<br>    ▼<br>[3. Citation Mapper] ──► Extract only cited excerpts for history<br>    │<br>    ▼<br>Store compressed history for next turn</pre><p>Each layer compounds the savings. Over a 10-message session with web search:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*H0szLGkCpbKZE3lnbiYmpw.png" /><figcaption>Table differential with &amp; without optimization</figcaption></figure><p>And here’s the real proof of the cost last month I spent on this project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*6y6_l6yhx5555K8_6N7YXA.png" /><figcaption>total api cost usage</figcaption></figure><p>That’s roughly a <strong>75% reduction in input token consumption</strong> across a typical session — with zero degradation in response quality.</p><h3>Final Thoughts</h3><p>Token optimization isn’t about being cheap. It’s about being <strong>precise</strong>. Models don’t get smarter because you sent them more noise — they get confused. Defluffing your prompts, caching your static context, and mapping citations instead of storing raw pages all make your AI layer more efficient <em>and</em> your responses more focused.</p><p>If you’re building a production AI app in React TypeScript, these three techniques are low-effort, high-reward starting points. Start with cache_control If you have a long system prompt, you&#39;ll see the impact immediately.</p><p><em>Found this useful? Follow for more deep-dives on building production AI applications with React and TypeScript.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f93e59aecb2" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/loseless-ai-token-consumption-techniques-i-used-for-web-app-4f93e59aecb2">Loseless AI Token Consumption Techniques I Used for Web App</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a Single AI-Generated Line of Code Crashed My Client’s Website]]></title>
            <link>https://blog.stackademic.com/how-a-single-ai-generated-line-of-code-crashed-my-clients-website-601bfa2ec0fc?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/601bfa2ec0fc</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[storytelling]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Wed, 18 Mar 2026 15:43:43 GMT</pubDate>
            <atom:updated>2026-03-19T07:40:47.470Z</atom:updated>
            <content:encoded><![CDATA[<h3>How a Single AI-Generated Line of Code Crashed My Client’s Site</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c1wREoaJNwwEEcba" /><figcaption>Photo by <a href="https://unsplash.com/@marcszeglat?utm_source=medium&amp;utm_medium=referral">Marc Szeglat</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>It was a beautiful day — coffee in hand, your vibe coding, everything just works fine. No bugs, no friction, just smooth flow and that rare feeling that you’re in complete control. Then it happens. One tiny change, just a single line suggested by AI, slips into your codebase. It looks harmless, even elegant. You hit save, deploy with confidence… and within minutes, your client’s website starts falling apart in ways you didn’t see coming.</p><p>The project itself wasn’t anything overly complex — and that was exactly the point. I deliberately chose a simple, reliable stack: Laravel paired with Bootstrap. No over-engineering, no fancy frameworks, no unnecessary abstractions. It was just a clean company profile website — mostly static content, a profile page, a bit of styling, and that’s it. The kind of project you expect to be stable from day one.</p><p>Everything was structured to minimize risk. Laravel handled the backend cleanly, routing was straightforward, and Bootstrap took care of the UI without any surprises. No heavy JavaScript, no real-time features, nothing that could easily spiral out of control. Honestly, it felt like one of those “nothing can go wrong here” setups.</p><p>And maybe that’s exactly why I let my guard down.</p><figure><img alt="image dewey sitcom" src="https://cdn-images-1.medium.com/max/480/1*fyxAMbAFHejgECWe1wf4zw.gif" /></figure><p>I’ve been using AI for coding for a while now, and honestly, it’s been a game-changer. From scaffolding boilerplate to suggesting quick fixes, it usually saves me a ton of time. Especially on small projects like this, where everything is supposed to be straightforward, AI feels like the perfect companion — fast, efficient, and “good enough” for most cases.</p><p>Inside my daily workflow, I rely heavily on Codex and Copilot directly in VS Code — one acting like a smart pair programmer suggesting lines as I type, the other more like a higher-level assistant that understands the bigger picture of the codebase.</p><p>When everything was ready — finished, polished, and deployed on the server — it worked perfectly. No errors, no warnings, no weird behavior. I did my usual checks, clicked through the pages, tested the main flows… all smooth. From my side, it looked like a clean, successful delivery.</p><figure><img alt="preview website before crash" src="https://cdn-images-1.medium.com/max/1024/1*69fMoQX7vbYRv34Ynm3woQ.png" /><figcaption>Normal web looking fine</figcaption></figure><p>Then my client reached out with what sounded like a simple request: they wanted a preview to appear when the website link was shared on social media — especially on WhatsApp. You know the one — thumbnail image, title, short description… the usual SEO/social preview stuff. Nothing complicated, just Open Graph tags and a bit of metadata to link look more professional and clickable. At that point, “Alright, that’s easy.”</p><p>Usually, I double-check everything before merging or pushing to main—reviewing changes carefully to ensure nothing slips through unnoticed.</p><p>And this time, maybe because it felt too small to fail. Just meta tags, just a tiny addition, nothing that should impact the core system. So instead of going through my usual thorough review, I skimmed it. A quick glance, a “yeah, looks fine,” and that was it.</p><p>Once it was shipped, a few hours went by quietly — no alerts, no obvious issues, nothing.</p><p>Then my client started trying to reach me.</p><p>At first, it didn’t feel urgent — just a message, then another. But the tone quickly shifted. Something wasn’t right. The site wasn’t behaving the way it should anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ux_zwfRjASvljYPGyXCSuQ.png" /><figcaption>The styles and scripts falling apart</figcaption></figure><p>The styles… gone. The layout looked broken, like the page had lost all its structure. Then I realized the scripts weren’t loading properly either. Interactions stopped working. It was as if the entire front-end layer had quietly collapsed.</p><p>I jumped straight into debugging mode, trying to trace what went wrong. At first, I thought it was something simple — maybe a broken path, a missing file, or a caching issue.</p><p>But then I found something… weird.</p><p>I inspected the CSS and JavaScript files, and they weren’t normal anymore. Instead of readable code, they had been transformed into what looked like Chinese or Japanese characters. At that point, my mind went straight to the worst-case scenario — I thought I had been hacked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*zBaBYcVALPfpYOSB3wtDuw.png" /><figcaption>CSS and JavaScript files suddenly turning into unreadable</figcaption></figure><p>I started checking everything — even things that weren’t directly related to the deployment. I went into GitHub, opened the security tab, and looked at the Dependabot alerts.</p><p>And there it was.</p><p>A warning about a CSRF vulnerability in webpack-dev-server</p><p>Which I used on my laravel-mix, but still… it just didn’t make any sense.</p><p>Yesterday, everything was completely normal. The same setup, the same server — no issues at all.</p><p>Because logically, adding meta tags for social preview shouldn’t affect how CSS and JavaScript are loaded.</p><p>I tried to change all the script and style into the CDN version, but it still didn&#39;t work.</p><p>Then, I jumped back, reviewed the latest changes again, and I realized the generated changes AI Code added this line :</p><pre>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-16&quot;&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*OnmGtyxQ8UMplU5u3w5QyQ.gif" /></figure><p>By forcing the page to use UTF-16, the browser started interpreting the entire document—and all linked resources—using a different encoding than expected. So instead of reading them as normal text, the browser tried to decode them with the wrong charset… and that’s why everything turned into those strange Chinese or Japanese-looking characters.</p><p>Lesson learned? You still matter, coders :) Don’t let AI take your entire job.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=601bfa2ec0fc" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-a-single-ai-generated-line-of-code-crashed-my-clients-website-601bfa2ec0fc">How a Single AI-Generated Line of Code Crashed My Client’s Website</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Jules is doing a Pretty Amazing thing!]]></title>
            <link>https://blog.stackademic.com/google-jules-is-doing-a-pretty-amazing-thing-10258565ef18?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/10258565ef18</guid>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 15:04:45 GMT</pubDate>
            <atom:updated>2025-07-03T11:25:04.657Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Jules is doing a Pretty Amazing thing! 🤯</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VFaRFvUO-pPT4Wix" /><figcaption>Photo by <a href="https://unsplash.com/@vackground?utm_source=medium&amp;utm_medium=referral">vackground.com</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Right after the Google Labs event last year in December, they announced something fun: they introduced “<a href="http://jules.google/">Jules</a>”</p><h4>What is Jules?</h4><p>Jules is an asynchronous, agentic coding assistant that integrates directly with your existing repositories. It clones your codebase into a secure Google Cloud virtual machine (VM), understands the full context of your project, and performs tasks such as:</p><ul><li>Writing tests</li><li>Building new features</li><li>Providing audio changelogs</li><li>Fixing bugs</li><li>Bumping dependency versions</li></ul><p>Jules operates asynchronously, allowing you to focus on other tasks while it works in the background. Upon completion, it presents its plan, reasoning, and a diff of the changes made. Jules is private by default; it doesn’t train on your private code, and your data stays isolated within the execution environment.</p><h4>How to get started?</h4><p>This guide will walk you through setting up Jules and running your first task.</p><p>⚫️ Visit Jules <a href="https://jules.google.com/">https://jules.google.com/</a><br>⚫️ Log in with your Google account<br>⚫️ Then accept the privacy notice (one-time)</p><p>After that, prepare for your GitHub. At the moment, Jules only works with GitHub and remains in beta.</p><p>⚫️ Click connect to GitHub<br>⚫️ Complete the login flow<br>⚫️ Choose <em>all</em> or specific repos that you want to connect to Jules<br>⚫️ You will be redirected back to Jules. If not, try refreshing the page</p><p>Once all done, you’ll see a <strong>repo selector</strong> where you can select the repo you want Jules to work with, and a prompt input box.</p><p><strong>Best scenario to use<br></strong>As we mentioned before, Jules for the moment best to use for just doing small tasks. Such as fixing bugs, writing tests, or just fixing small typos.</p><p>To start with your first task on Jules, you can pick the project that is connected to your GitHub with the repo selector.</p><p>⚫️ Pick a repository from the repo selector<br>⚫️ Choose the branch you want Jules to work on. The default branch will be selected already. You do not have to modify this unless you want Jules to work on a specific branch.<br>⚫️ Write a <strong>clear</strong>, <strong>specific</strong> prompt. For example in here I have a personal website built using Astro.js, but it still lacks mobile responsiveness and accessibility coverage.<br>⚫️ My prompt will be “Make the whole website mobile-friendly and accessible”<br>⚫️ Click Give me a plan</p><p>Once you submit a task, Jules will generate a plan. You can review and approve it before any code changes are made.</p><figure><img alt="example prompt to use jules make web mobile friendly and accessible" src="https://cdn-images-1.medium.com/max/1024/1*Ce0nfQ4y_5UhdhfUwRUGNg.jpeg" /><figcaption>jules runs prompt that planned before</figcaption></figure><p>Not only just make changes to the code, but Jules will also help you merge it to your main branch after all finished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rS649cBxuACyLUskyVH7bg.png" /><figcaption>jules just made new branch enhance-readme</figcaption></figure><p><strong>Summary<br></strong>Jules is currently in beta and works exclusively with GitHub repositories. It’s optimized for smaller tasks like bug fixes, test writing, and minor improvements rather than large-scale refactoring.<br>Jules performs best with <strong>clear, specific instructions</strong> and will always transform and update itself, making the best version possible.</p><p><em>So, ready to experience the future of coding assistance? Jules is waiting to transform your development workflow.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10258565ef18" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/google-jules-is-doing-a-pretty-amazing-thing-10258565ef18">Google Jules is doing a Pretty Amazing thing!</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Rise of Lynx.js: A Newcomer JavaScript Framework Fueling TikTok’s Innovation]]></title>
            <link>https://blog.stackademic.com/the-rise-of-lynx-js-a-newcomer-javascript-framework-fueling-tiktoks-innovation-8cd1ec514563?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cd1ec514563</guid>
            <category><![CDATA[lynx]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 09:19:02 GMT</pubDate>
            <atom:updated>2025-05-08T15:27:22.706Z</atom:updated>
            <content:encoded><![CDATA[<p>Frameworks like React Native and Flutter have long dominated cross-platform development, but Lynx JS introduces a fresh approach that seamlessly bridges web and mobile development, built on top of the React Engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sRLxd_WQ63aDJFQI" /><figcaption>Photo by <a href="https://unsplash.com/@zmachacek?utm_source=medium&amp;utm_medium=referral">Zdeněk Macháček</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>And lately, I’ve been busy balancing everything: work, life &amp; hobby. Suddenly, just got news about new development tools from TikTok named Lynx. <br>Yes, you heard it! Named from a medium-sized wildcat known for its distinctive appearance and elusive nature.</p><p>From that moment made my curiosity to try! And here’s the review, the story of me trying Lynx.js</p><h4>Introduction: Release Date</h4><p>5th March 2025 marked the birth of Lynx.js, a <em>family</em> of technologies empowering developers to use their existing web skills to create truly native UIs for both mobile and web from a single codebase. Designed for diverse use cases and rich interactivity, Lynx delivers vibrant and engaging UIs for large-scale apps like TikTok, featuring a speedy, versatile rendering engine, performance-driven dual-threaded UI programming, modern Rust-based tooling, and more!</p><p>One week after the release date, I got an update post from daily.dev about the new JavaScript framework Lynx.js, right after that I’m starting to try it.</p><h4>Initial Plan: Blog App</h4><p>I was thinking to learn Lynx.js, not just randomly trying its component without planning what the app was going to make. Then the idea that comes to my mind is creating a blog app, a simple yet powerful implementation for a simple CRUD operation.</p><p>Looking for some inspiration on Dribble, I found this perfect UI Design Blog App by Syed Raju <a href="https://dribbble.com/shots/20805109-Blog-App?utm_source=Clipboard_Shot&amp;utm_campaign=syedraju&amp;utm_content=Blog%20App&amp;utm_medium=Social_Share&amp;utm_source=Clipboard_Shot&amp;utm_campaign=syedraju&amp;utm_content=Blog%20App&amp;utm_medium=Social_Share">https://dribbble.com/shots/20805109-Blog-App</a></p><figure><img alt="Mobile blog app design by Syed Raju on Dribble" src="https://cdn-images-1.medium.com/max/752/0*GH-JM8hRt2GDMTA5" /><figcaption>Blog App by Syed Raju on Dribble</figcaption></figure><h4>Configuration: Blog App</h4><p>To start development, what we need is to install <a href="https://lynxjs.org/guide/start/quick-start.html#ios-simulator-platform=macos-arm64,explorer-platform=ios-simulator">LynxExplorer</a>.<br>Then run this command to create the project</p><pre>npm create rspeedy@latest</pre><p>Full documentation, quick start of Lynx.js right <a href="https://lynxjs.org/guide/start/quick-start.html">here</a></p><p>Fast-forward, after the configuration setup is finished, time to dive in.</p><figure><img alt="screenshot lynxeplorer with ios simulator iphone 13" src="https://cdn-images-1.medium.com/max/320/1*jC4gqGlVVDHhJQq_XEf4Qg.png" /><figcaption>First Look LynxExplorer On iOS Simulator</figcaption></figure><h4>Building: Blog App</h4><p>Because Lynx.js uses React Engine, all the existing components are similar to React Native’s components.</p><p>Let’s take a look at how we place all elements in Lynx.js.</p><pre>// hello world in lynx<br>export const App = () =&gt; {<br>  return (<br>    &lt;view style=&quot;padding:5px;width:100%; height:100%;&quot;&gt;<br>      &lt;text className=&quot;title&quot;&gt;Hello Readers&lt;/text&gt;<br>    &lt;/view&gt;<br>  );<br>};<br><br>//hello world in react native<br>export const App = () =&gt; {<br>  return (<br>    &lt;View style=&quot;padding:5px;width:100%; height:100%;&quot;&gt;<br>      &lt;Text className=&quot;title&quot;&gt;Hello Readers&lt;/Text&gt;<br>    &lt;/View&gt;<br>  );<br>};</pre><p>One of the differences is a capitalized letter at the first. Lynx.js brings a vibe of how you code for the web starts with lowercase.</p><h4>Review: Pros &amp; Cons</h4><p>What else can we see from Lynx.js? <br>Gradient background, all along in React Native, to produce a gradient, we need help from another library or/3rd party. With Lynx.js, we can easily do that as we do on the web. Define a custom class, then set the value.</p><pre>/* global.css */<br>.bg-midnight-gradient {<br>  background: linear-gradient(<br>    to right,<br>    rgb(29, 78, 216),<br>    rgb(30, 64, 175),<br>    rgb(17, 24, 39)<br>  );<br>}</pre><p>You may import it into your components, like this, set the class name we defined in the component.</p><pre>const Header = () =&gt; {<br>  return (<br>    &lt;view<br>      class=&quot;bg-midnight-gradient container&quot;<br>    &gt;<br>      &lt;text class=&quot;text-white&quot;&gt;<br>        Blogbust<br>      &lt;/text&gt;<br>    &lt;/view&gt;<br>  );<br>};<br><br>export default Header;</pre><figure><img alt="screenshot how gradient background works on lynx.js" src="https://cdn-images-1.medium.com/max/400/1*QqEIeajO-iArTbn3fuBMFQ.png" /><figcaption>Gradient Background with Lynx</figcaption></figure><p>Another one is how to define route/navigation currently, when I write this review, the only way to handle multiple pages in Lynx is using react-router.</p><pre>import { useNavigate, useLocation } from &#39;react-router&#39;;<br>import { IMAGE } from &#39;../../constants/images.ts&#39;;<br><br>const BottomNavigation = () =&gt; {<br>  const navigate = useNavigate();<br>  const location = useLocation();<br><br>  const handleNavigation = (path: string) =&gt; {<br>    navigate(path);<br>  };<br><br>  const isActive = (path: string) =&gt; {<br>    return location.pathname === path;<br>  };<br><br>  return (<br>    &lt;view&gt;<br>      &lt;view&gt;<br>        {/* Home Menu */}<br>        &lt;view<br>        bindtap={() =&gt; handleNavigation(&#39;/home&#39;)}&gt;<br>          &lt;image<br>            src={<br>              isActive(&#39;/home&#39;) || isActive(&#39;/&#39;)<br>                ? IMAGE.ICON_HOME_ACTIVE<br>                : IMAGE.ICON_HOME<br>            }<br>            style={{<br>              width: &#39;20px&#39;,<br>              height: &#39;20px&#39;,<br>            }}<br>          /&gt;<br>          &lt;text&gt;<br>            Home<br>          &lt;/text&gt;<br>        &lt;/view&gt;<br><br>        {/* Profile Menu */}<br>        &lt;view<br>          bindtap={() =&gt; handleNavigation(&#39;/profile&#39;)}<br>        &gt;<br>          &lt;image<br>            src={<br>              isActive(&#39;/profile&#39;)<br>                ? IMAGE.ICON_PROFILE_ACTIVE<br>                : IMAGE.ICON_PROFILE<br>            }<br>            style={{<br>              width: &#39;20px&#39;,<br>              height: &#39;20px&#39;,<br>            }}<br>          /&gt;<br>          &lt;text&gt;<br>            Profile<br>          &lt;/text&gt;<br>        &lt;/view&gt;<br>      &lt;/view&gt;<br>    &lt;/view&gt;<br>  );<br>};<br><br>export default BottomNavigation;</pre><p>What if we need a library to use, for example, TailwindCSS?<br>To use a library is kinda tricky at the moment, still lacks its documentation, notes review from the community/developers themselves.</p><p>But yes, you can leverage 3rd party to use like any other JavaScript framework/library. Here’s how I managed to integrate TailwindCSS into Lynx’s project.</p><p>Install the necessary package first, like rsbuild-plugin-tailwind and the tailwindcss itself. Fyi, Lynx.js adapts rspack for the building tool called lynxjs/rspeedy based on Rust.</p><pre>npm i tailwindcss @lynx-contrib/tailwind-preset rsbuild-plugin-tailwindcss</pre><p>Create a tailwindcss configuration as usual, then import the latest rest libraries into lynx.config.ts</p><pre>import { defineConfig } from &#39;@lynx-js/rspeedy&#39;;<br>import { pluginTailwindCSS } from &#39;rsbuild-plugin-tailwindcss&#39;;<br><br>export default defineConfig({<br>  plugins: [<br>    ...,<br>    pluginTailwindCSS(),<br>  ],<br>});</pre><p>Now, we can use className in our component similarly to how we use Tailwind for the web. Cool right?</p><pre>import Header from &#39;../components/header/index.tsx&#39;;<br>import Horizontal from &#39;../components/scroller-item/Horizontal.tsx&#39;;<br>import Vertical from &#39;../components/scroller-item/Vertical.tsx&#39;;<br>import Scroller from &#39;../components/scroller/index.tsx&#39;;<br>import { blogs } from &#39;../constants/blogs.ts&#39;;<br>import { categories } from &#39;../constants/categories.ts&#39;;<br>import { IMAGE } from &#39;../constants/images.ts&#39;;<br><br>const Home = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;Header /&gt;<br>      &lt;view className=&quot;bg-stone-100&quot;&gt;<br>        &lt;Scroller<br>          oritentation=&quot;horizontal&quot;<br>          styles={{<br>            width: &#39;calc(100% - 1px)&#39;,<br>            height: &#39;100px&#39;,<br>            paddingBottom: &#39;20px&#39;,<br>            paddingTop: &#39;20px&#39;,<br>            paddingLeft: &#39;12px&#39;,<br>            paddingRight: &#39;12px&#39;,<br>            borderRadius: &#39;1px&#39;,<br>          }}<br>        &gt;<br>          {categories.map((item, index) =&gt; (<br>            &lt;Horizontal index={index} item={item} /&gt;<br>          ))}<br>        &lt;/Scroller&gt;<br>      &lt;/view&gt;<br>      &lt;view className=&quot;h-full p-4&quot;&gt;<br>        &lt;view className=&quot;flex justify-between items-center&quot;&gt;<br>          &lt;text className=&quot;font-bold leading-normal text-2xl&quot;&gt;Games&lt;/text&gt;<br>          &lt;image src={IMAGE.ICON_FILTER} className=&quot;w-6 h-6&quot; /&gt;<br>        &lt;/view&gt;<br>        &lt;Scroller<br>          oritentation=&quot;vertical&quot;<br>          styles={{<br>            width: &#39;calc(100% - 1px)&#39;,<br>            height: &#39;calc(100% - 280px)&#39;,<br>            paddingBottom: &#39;20px&#39;,<br>          }}<br>        &gt;<br>          {blogs.map((item, index) =&gt; (<br>            &lt;Vertical item={item} /&gt;<br>          ))}<br>        &lt;/Scroller&gt;<br>      &lt;/view&gt;<br>    &lt;/&gt;<br>  );<br>};<br><br>export default Home;</pre><figure><img alt="showcase final output blog app with lynx.js" src="https://cdn-images-1.medium.com/max/330/1*nDopG40BcmS3jILWQjSafQ.gif" /><figcaption>Final Output Blog App With Lynx.js</figcaption></figure><h4>Conclusion: IMO</h4><p>After exploring Lynx.js, it’s clear this framework brings an interesting approach to web development and shines in certain areas, even currently, as I write this blog, still in beta version.</p><p>However, Lynx.js still has room to grow. Looking ahead, I hope future updates will bring:</p><ol><li>More comprehensive documentation, especially for third-party integrations</li><li>Native navigation solutions beyond React-Router</li><li>Streamlined library integration processes</li><li>Expanded component library and styling options</li><li>Better community resources and examples</li></ol><p>Lynx.js shows promise with its web-like approach to development, but it needs continued refinement to reach its full potential. The foundation is solid, and with active development and community growth, it could become a compelling option for developers seeking performance and familiar web paradigms.</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://differ.blog/inplainenglish"><strong>Differ</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cd1ec514563" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/the-rise-of-lynx-js-a-newcomer-javascript-framework-fueling-tiktoks-innovation-8cd1ec514563">The Rise of Lynx.js: A Newcomer JavaScript Framework Fueling TikTok’s Innovation</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Dependency Injection In JavaScript With Real Action]]></title>
            <link>https://blog.stackademic.com/understanding-dependency-injection-in-javascriptwith-real-action-f000749b1a17?source=rss-500caf978c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f000749b1a17</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Raihan Nismara]]></dc:creator>
            <pubDate>Tue, 03 Sep 2024 10:06:11 GMT</pubDate>
            <atom:updated>2024-09-12T00:16:15.624Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever felt like your codebase is a tangled mess of dependencies, making every change feel like you’re pulling on a loose thread in a sweater? We’ve all been there. But what if I told you there’s a way to keep your JavaScript code clean, organized, and flexible without losing your sanity? Enter Dependency Injection (DI) — a powerful pattern that can transform the way you write and maintain your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VkPj76hIgUwNBBBF" /><figcaption>Photo by <a href="https://unsplash.com/@diana_pole?utm_source=medium&amp;utm_medium=referral">Diana Polekhina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, we’re going to dive into the world of Dependency Injection in JavaScript. But we won’t stop there; we’ll roll up our sleeves and see how this pattern comes to life in a real-world React application. Whether you’re a seasoned developer or just starting, by the end of this read, you’ll not only understand the magic of Dependency Injection but also how to wield it like a pro in your React projects. Let’s get started!</p><h3>What the heck is Dependency Injection</h3><p>Imagine you’re building a robot, and it needs many tools to do its job. You could glue those tools onto the robot’s hands, but what if you want to change a tool later? Or what if you need to test the robot with different tools? That’s where Dependency Injection (DI) comes in!</p><p>Dependency Injection (DI) is a design pattern in software development that helps create more flexible, maintainable, and testable code. It’s commonly used in object-oriented programming (OOP) and plays a crucial role in managing dependencies between different parts of an application.</p><p>At its core, Dependency Injection is about separating the creation of an object’s dependencies from the object itself. Instead of an object creating its dependencies, these are provided to it, usually by an external entity known as a <strong>Dependency Injector</strong> or <strong>Container</strong>.</p><p>Instead of gluing the tools directly to the robot, you give the robot a toolbox. The robot doesn’t know or care what tools are in there — it just uses whatever you give it. This means you can easily swap out a hammer for a wrench or test with a toy hammer instead of a real one.</p><p>Here’s how it might look in code:</p><pre>class Hammer {<br>  hit() {<br>    return &quot;Bang!&quot;;<br>  }<br>}<br><br>class Robot {<br>  private tool: Hammer;<br><br>  constructor(tool: Hammer) {<br>    this.tool = tool;<br>  }<br><br>  useTool() {<br>    return this.tool.hit();<br>  }<br>}<br><br>// Injecting the hammer tool into the robot<br>const hammer = new Hammer();<br>const robot = new Robot(hammer);</pre><p>You see the code is more flexible, if your robot suddenly needs a wrench instead of a hammer, you don’t have to rebuild the whole robot. Just pop in the new tool!</p><h3>Dependency Injection In React Live Action</h3><p>Now, let’s make it fun and easy to understand Dependency Injection (DI) in React!</p><p>Imagine you’re building a weather app, and you have one WeatherService that fetches weather data. Instead of directly creating an instance of WeatherService inside your React component, you inject it as a prop. This way, you can easily swap out the service for a mock one during testing or use a different service altogether.</p><pre>class WeatherService {<br>  getWeather(city) {<br>    return `Weather in ${city} is sunny!`;<br>  }<br>}</pre><p>Now we can inject the service into the component like this:</p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import WeatherComponent from &#39;./WeatherComponent&#39;;<br><br>const weatherService = new WeatherService();<br><br>ReactDOM.render(<br>  &lt;WeatherComponent weatherService={weatherService} city=&quot;New York&quot; /&gt;,<br>  document.getElementById(&#39;root&#39;)<br>);</pre><p>So, if you want to use a different weather service you can swap it out when injecting the dependency. Cool right? It gives you flexibility and is easy to maintain on your code.</p><h3>Summary</h3><p>Dependency Injection is like giving your robot a customizable toolbox. It keeps things flexible, makes testing easier, and helps you manage your code like a pro.</p><p>Dependency injection in React is conceptually similar to how we use <strong>props</strong> and <strong>custom hooks</strong>. So next time you’re building a React app, think about where you can use Dependency Injection to improve your components!</p><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f000749b1a17" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/understanding-dependency-injection-in-javascriptwith-real-action-f000749b1a17">Understanding Dependency Injection In JavaScript With Real Action</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>