2.0.0 • Published 3 years ago

@everlast-brands/local-collection v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Everlast Brands Local Collections

Local collections are equivalent to collections other than they store data in json documents on the server or dev machine making them ideal for building software locally before setting up external storage strategies such as a database or google firestore. Ideally local collections are best when used in dev and test they don't scale as well as a database in production.

Installation

yarn add @everlast-brands/local-collection
// or
npm install @everlast-brands/local-collection

Setup

import express from "express";
import { Collection } from "@everlast-brands/local-collection";

const app = express();

// add collections to the server
app.use((req, res, next) => {
  req.collections = {
    user: new Collection('users'),
    messages: new Collection('messages'),
    // ...other collections
  }
})

// ...rest of app

Usage

app.post("/users", async (req, res) => {
  const userData = req.body.user;

  const result = await req.collections.user.create(userData);
});