UNPKG

jsonroutedb

Version:

A simple Node.js package to access non-binary files using a path-like string.

48 lines (36 loc) 1.78 kB
# jsonroutedb A simple Node.js package that allows you to access the content of non-binary files (like `.txt`, `.html`, `.css`, `.js`, etc.) stored within a `data` directory using a path-like string. ## Installation ```bash npm install jsonroutedb ``` ## Usage After installing, you can use the `choose` function to retrieve the content of files based on their location within the `data` directory. The path is specified as a string with folder and file names separated by `" TO "`. ```javascript const db = require('jsonroutedb'); // async function getData() { const textContent = await db.choose('app TO test TO test.txt'); if (textContent !== null) { console.log('Content of test.txt:\n', textContent); } else { console.error('Could not find or read the file: app/test/test.txt'); } const htmlContent = await db.choose('website TO pages TO index.html'); if (htmlContent !== null) { console.log('Content of index.html:\n', htmlContent); } else { console.error('Could not find or read the file: website/pages/index.html'); } } getData(); async function manageData() { const createDbResult = await db.createDatabase('my_first_database'); console.log(createDbResult); // Output: Database (folder) created at: /Users/yourusername/.jsonroutedb_data/my_first_database const createFolderResult = await db.createFolder('my_first_database TO subfolder'); console.log(createFolderResult); // Output: Folder created at: /Users/yourusername/.jsonroutedb_data/my_first_database/subfolder const contents = await db.choose('my_first_database TO subfolder TO my_data.txt'); if (contents !== null) { console.log('Content of my_data.txt:', contents); } else { console.error('Could not find or read the file.'); } } manageData();