Get started with lowdb CDN

MIT licensed

LowDB is a minimalist NoSQL database written in JS for local data storage.

Tags:
  • flat
  • file
  • local
  • database
  • storage
  • JSON
  • lo-dash
  • lodash
  • underscore
  • localStorage
  • embed
  • embeddable

Stable version

Copied!

How to start using lowdb CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with lowdb CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/lowdb/7.0.1/low.min.js"></script>
</head>
<body>
  <button id="add">Add Item</button>
  <ul id="items"></ul>

  <script>
    const db = low('db.json'); // Initialize a new database

    db.defaults({ items: [] }).write(); // Set up the items array if it doesn't exist

    const items = db.get('items');

    const addBtn = document.getElementById('add');
    const itemsList = document.getElementById('items');

    addBtn.addEventListener('click', () => {
      const newItem = { id: Date.now(), name: `Item ${items.value.length + 1}` };
      items.push(newItem).write();
      itemsList.innerHTML += `<li>${newItem.name}</li>`;
    });

    items.value.forEach((item) => {
      itemsList.innerHTML += `<li>${item.name}</li>`;
    });
  </script>
</body>
</html>

All versions