Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

fake-db

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fake-db

Fake database to mock REST API

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Fake database to mock REST API

When do I need this?

Fake Database could be usefule for mocking REST API during development of an application. Check out REST API for TodoMVC app

Example

var express = require('express');
var app = express();

var FakeDB = require('fake-db');
var db = new FakeDB([
    {title: 'foo'},
    {title: 'bar'}
]);

app.get('/api/todos', function(req, res) {
  db.getCollection().then(function(collection) {
    res.json(collection);
  });
});

app.listen(3000);

API

All methods emulate async under the hood and return a promise.

getCollection

var collection = [
    {title: 'foo'},
    {title: 'bar'}
];
var db = new FakeDB(collection);

db.getCollection().then(function(collection) {
    // [{...}, {...}]
    console.log(collection);
});

getItem

var collection = [
    {title: 'foo'},
    {title: 'bar'}
];
var db = new FakeDB(collection);

db.getItem(1).then(function(item) {
    // {title: 'foo'}
    console.log(item);
});

setItem

var collection = [
    {title: 'foo'},
    {title: 'bar'}
];
var db = new FakeDB(collection);

db.setItem(3)
    .then(function() {
        return db.getCollection()
    })
    .then(function(collection) {
        // 3
        console.log(collection.length);
    });

id could be ommited and will be set automatically

removeItem

var collection = [
    {title: 'foo'},
    {title: 'bar'}
];
var db = new FakeDB(collection);

db.removeItem(1)
    .then(function() {
        return db.getCollection()
    })
    .then(function(collection) {
        // 1
        console.log(collection.length);
    });

FAQs

Package last updated on 09 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts