CSV File-based Database

0.2.2 · abandoned · verified Wed Apr 22

csv-db is a lightweight, file-based database for Node.js, initially designed as a teaching aid for workshops requiring a simple data persistence layer. It stores data in plain CSV files, using newlines for row separation and semicolons for field separation. The current stable version, 0.2.2 (last published over eight years ago), relies on Promises for asynchronous CRUD (Create, Read, Update, Delete) operations, a significant evolution from its initial synchronous implementation. Its primary differentiators are extreme simplicity and direct file storage, making it suitable for minimal persistence needs, proof-of-concept applications, or educational contexts where understanding basic data storage is key. It lacks advanced database features such as indexing, complex querying, or transaction management. Due to its age and lack of updates, its release cadence is effectively nonexistent.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing `csv-db` with a file and column names, then fetching all records and a specific record by ID.

const CsvDb = require('csv-db');
const fs = require('fs');

// Create a dummy CSV file for demonstration
const filePath = 'example.csv';
const initialData = '1;admin;secret;\n2;user;password;';
fs.writeFileSync(filePath, initialData);

const csvDb = new CsvDb(filePath, ['id', 'username', 'password']);

csvDb.get().then((data) => {
  console.log('All data:', data);
  // Expected output: [{ id: '1', username: 'admin', password: 'secret' }, { id: '2', username: 'user', password: 'password' }]
}).catch((err) => {
  console.error('Error fetching all data:', err);
});

csvDb.get('1').then((data) => {
  console.log('Data for ID 1:', data);
  // Expected output: [{ id: '1', username: 'admin', password: 'secret' }]
}).catch((err) => {
  console.error('Error fetching data by ID:', err);
});

// Clean up the dummy file
process.on('exit', () => {
  if (fs.existsSync(filePath)) {
    fs.unlinkSync(filePath);
    console.log(`Cleaned up ${filePath}`);
  }
});

view raw JSON →