{"id":18111560,"url":"https://github.com/c3o-git/secure-offline-json-db","last_synced_at":"2026-02-08T16:32:58.407Z","repository":{"id":259392841,"uuid":"877628049","full_name":"c3o-git/secure-offline-json-db","owner":"c3o-git","description":"Secure JSON Offline Database is A robust, secure offline JSON database for Next.js and React Native applications. This package offers schema validation, rate limiting, and strict file permissions to protect your data, making it ideal for modern web and mobile apps. It simplifies CRUD operations while ensuring data integrity and security. ","archived":false,"fork":false,"pushed_at":"2024-10-24T12:23:30.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T08:23:04.714Z","etag":null,"topics":["crud-operations","data-security","file-based-database","joi-validation","json-database","json-storage","nextjs-database","nodejs","npm-package","offline-database","offline-storage","rate-limiting","react-native-database","schema-validation","secure-json","secure-offline-json-db"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/secure-offline-json-db","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c3o-git.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-24T00:52:25.000Z","updated_at":"2025-01-09T15:42:55.000Z","dependencies_parsed_at":"2024-10-25T03:27:26.218Z","dependency_job_id":"e7370f2e-af1b-486d-a3a0-f3364e2778f5","html_url":"https://github.com/c3o-git/secure-offline-json-db","commit_stats":null,"previous_names":["c3o-git/secure-offline-json-db"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/c3o-git/secure-offline-json-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c3o-git%2Fsecure-offline-json-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c3o-git%2Fsecure-offline-json-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c3o-git%2Fsecure-offline-json-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c3o-git%2Fsecure-offline-json-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c3o-git","download_url":"https://codeload.github.com/c3o-git/secure-offline-json-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c3o-git%2Fsecure-offline-json-db/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267827503,"owners_count":24150350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud-operations","data-security","file-based-database","joi-validation","json-database","json-storage","nextjs-database","nodejs","npm-package","offline-database","offline-storage","rate-limiting","react-native-database","schema-validation","secure-json","secure-offline-json-db"],"created_at":"2024-11-01T01:06:15.215Z","updated_at":"2026-02-08T16:32:57.955Z","avatar_url":"https://github.com/c3o-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/secure-offline-json-db\"\u003e\r\n     \u003cimg src=\"https://c3o.onrender.com/images/secure-json-db.png\" width=\"300\" height=\"300\" alt=\"SecureOfflineJsonDb\"\u003e\r\n    \u003c/a\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n# Secure Json Offline Database\r\n\r\n`secure-offline-json-db` is an offline JSON database designed with security features such as input validation, rate limiting, file permissions, and logging. It allows you to store, retrieve, and manage records in a secure, JSON-based file system while preventing common attack vectors.\r\n\r\n## Features\r\n\r\n**Schema Validation**: Uses **Joi** to validate records based on customizable schemas.\r\n**Rate Limiting**: Protects against overuse by rate limiting incoming requests.\r\n**File Permissions**: Ensures that the database file has strict read/write access.\r\n**Logging**: Integrates with **morgan** to log requests and monitor system access.\r\n**CRUD Operations**: Supports creating, reading, updating, and deleting records.\r\n\r\n## Installation\r\n\r\nTo install the package, run:\r\n\r\n```bash\r\nnpm install secure-offline-json-db\r\n```\r\n## Usage\r\n\r\n### 1. Initializing the Database\r\n\r\nTo use `secure-offline-json-db`, import the package and create an instance by passing the path to the JSON file and the Joi schema for record validation.\r\n\r\n```javascript\r\nconst JsonOfflineDb = require('secure-offline-json-db');\r\nconst Joi = require('joi');\r\n\r\n// Define the schema for records\r\nconst recordSchema = Joi.object({\r\n    id: Joi.number().required(),\r\n    name: Joi.string().min(3).required(),\r\n    age: Joi.number().integer().min(18).max(100).required(),\r\n});\r\n\r\n// Initialize the database\r\nconst db = new JsonOfflineDb('./db.json', recordSchema);\r\n```\r\n### 2. CRUD Operations\r\n\r\n**Read All Records**\r\nTo retrieve all records stored in the JSON database:\r\n\r\n```javascript\r\nconst records = db.read();\r\nconsole.log(records);\r\n```\r\n**Create a Record**\r\nTo add a new record to the database, pass the record object to the `create` method:\r\n\r\n```javascript\r\nconst newRecord = {\r\n    id: 1,\r\n    name: \"John Doe\",\r\n    age: 25,\r\n};\r\n\r\ndb.create(newRecord);\r\n```\r\n**Update a Record**\r\nTo update an existing record, pass the `id` of the record and an object with the updated values:\r\n\r\n```javascript\r\nconst updatedRecord = db.update(1, { age: 26 });\r\nconsole.log(updatedRecord);\r\n```\r\n\r\n**Delete a Record**\r\n\r\nTo delete a record by its `id`, use the `delete` method:\r\n\r\n```javascript\r\ndb.delete(1);\r\nconsole.log(\"Record deleted successfully.\");\r\n```\r\n\r\n### 3. Security Features\r\n\r\n**Input Validation**\r\n\r\nRecords are validated against the schema you provide when initializing the database. If a record does not meet the validation criteria, an error will be thrown.\r\n\r\n```javascript\r\ntry {\r\n    const invalidRecord = { id: 2, name: \"A\", age: 17 }; // Invalid record\r\n    db.create(invalidRecord);\r\n} catch (error) {\r\n    console.error(error.message); // Validation error\r\n}\r\n```\r\n\r\n**Rate Limiting**\r\n\r\nTo prevent excessive requests, `secure-offline-json-db` includes rate limiting. You can apply rate limiting to IP addresses before performing database operations.\r\n\r\n```javascript\r\nawait db.applyRateLimit(req.ip); // Rate limit applied\r\n```\r\n\r\n**File Permissions**\r\nThe database file (`db.json`) is created with strict read/write permissions (owner-only). This prevents unauthorized access to the database file at the filesystem level.\r\n\r\n**Logging**\r\nThe package supports logging of incoming requests through **morgan**. You can log request data, errors, and response times to monitor activity.\r\n\r\n```javascript\r\nconst morgan = require('morgan');\r\napp.use(morgan('dev')); // Logs HTTP requests\r\n```\r\n\r\n### **Using with Next.js**\r\n\r\nYou can easily integrate `secure-offline-json-db` with a Next.js backend to manage your offline database. Below is an example of using the package in Next.js API routes.\r\n\r\n1. Install **Next.js**:\r\n\r\n    ```bash\r\n    npx create-next-app@latest\r\n    cd my-nextjs-app\r\n    ```\r\n\r\n2. Install **secure-json-db** within your Next.js project:\r\n\r\n    ```bash\r\n    npm install secure-offline-json-db\r\n    ```\r\n\r\n3. Create an API route in Next.js (`pages/api/records.js`):\r\n\r\n    ```javascript\r\n    import JsonOfflineDb from 'secure-offline-json-db';\r\n    import Joi from 'joi';\r\n\r\n    const recordSchema = Joi.object({\r\n        id: Joi.number().required(),\r\n        name: Joi.string().min(3).required(),\r\n        age: Joi.number().integer().min(18).max(100).required(),\r\n    });\r\n\r\n    const db = new JsonOfflineDb('./db.json', recordSchema);\r\n\r\n    export default async function handler(req, res) {\r\n        const { method } = req;\r\n\r\n        try {\r\n            switch (method) {\r\n                case 'GET':\r\n                    const records = db.read();\r\n                    res.status(200).json(records);\r\n                    break;\r\n                case 'POST':\r\n                    const newRecord = db.create(req.body);\r\n                    res.status(201).json(newRecord);\r\n                    break;\r\n                case 'PUT':\r\n                    const updatedRecord = db.update(req.body.id, req.body);\r\n                    res.status(200).json(updatedRecord);\r\n                    break;\r\n                case 'DELETE':\r\n                    db.delete(req.body.id);\r\n                    res.status(200).json({ message: \"Record deleted\" });\r\n                    break;\r\n                default:\r\n                    res.setHeader('Allow', ['GET', 'POST', 'PUT', 'DELETE']);\r\n                    res.status(405).end(`Method ${method} Not Allowed`);\r\n            }\r\n        } catch (error) {\r\n            res.status(400).json({ error: error.message });\r\n        }\r\n    }\r\n    ```\r\n\r\n4. Start the Next.js server:\r\n\r\n    ```bash\r\n    npm run dev\r\n    ```\r\n\r\nNow, you can interact with the secure JSON database via API routes in Next.js.\r\n\r\n---\r\n\r\n### **Using with React Native**\r\n\r\nYou can access the **secure-offline-json-db** backend via API calls in a **React Native** app.\r\n\r\n1. Install **axios** in your React Native project:\r\n\r\n    ```bash\r\n    npm install axios\r\n    ```\r\n\r\n2. Use the `axios` library to interact with the database:\r\n\r\n    ```javascript\r\n    import axios from 'axios';\r\n    import React, { useEffect, useState } from 'react';\r\n    import { View, Text, FlatList, StyleSheet } from 'react-native';\r\n\r\n    const App = () =\u003e {\r\n        const [records, setRecords] = useState([]);\r\n\r\n        useEffect(() =\u003e {\r\n            axios.get('http://localhost:4000/api/records')\r\n                .then(response =\u003e {\r\n                    setRecords(response.data);\r\n                })\r\n                .catch(error =\u003e {\r\n                    console.error('Error fetching records:', error);\r\n                });\r\n        }, []);\r\n\r\n        return (\r\n            \u003cView style={styles.container}\u003e\r\n                \u003cFlatList\r\n                    data={records}\r\n                    keyExtractor={item =\u003e item.id.toString()}\r\n                    renderItem={({ item }) =\u003e (\r\n                        \u003cText\u003e{item.name} - {item.age} years old\u003c/Text\u003e\r\n                    )}\r\n                /\u003e\r\n            \u003c/View\u003e\r\n        );\r\n    };\r\n\r\n    const styles = StyleSheet.create({\r\n        container: {\r\n            flex: 1,\r\n            justifyContent: 'center',\r\n            padding: 16,\r\n        },\r\n    });\r\n\r\n    export default App;\r\n    ```\r\nIn this example, your React Native app makes requests to the `secure-offline-json-db` backend running on `localhost:4000`.\r\n\r\n---\r\n\r\n### **Security Best Practices**\r\n\r\n**Rate Limiting**: Ensure rate limiting is configured to prevent abuse.\r\n**Environment Variables**: Use environment variables for sensitive data.\r\n**File Permissions**: Ensure the database file is protected with restricted permissions.\r\n**Validation**: Always validate inputs to prevent invalid or malicious data from entering the system.\r\n\r\n---\r\n\r\n### **Changelog**\r\n\r\n#### **1.0.0**\r\n- Initial release with support for JSON storage, schema validation, rate limiting, and request logging.\r\n\r\n---\r\n\r\n### **License**\r\n\r\nMIT License\r\n\r\n---\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc3o-git%2Fsecure-offline-json-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc3o-git%2Fsecure-offline-json-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc3o-git%2Fsecure-offline-json-db/lists"}