Skip to content
A client side service based on feathers-memory that persists to LocalStorage
JavaScript
Find file
Latest commit abf08e3 @ekryski ekryski fix typo in changelog

README.md

feathers-localstorage

Build Status

A client side service based on feathers-memory that persists to LocalStorage or AsyncStorage

Installation

npm install feathers-localstorage --save

Documentation

Please refer to the Feathers database adapter documentation for more details or directly at:

Complete Example

Here is an example of a Feathers server with a messages localstorage service that supports pagination. It uses the node module localstorage-memory.

var feathers = require('feathers');
var bodyParser = require('body-parser');
var rest = require('feathers-rest');
var socketio = require('feathers-socketio');
var localstorage = require('feathers-localstorage');
var storage = require('localstorage-memory');

// Create a feathers instance.
const app = feathers()
  // Enable REST services
  .configure(rest())
  // Enable Socket.io services
  .configure(socketio())
  // Turn on JSON parser for REST services
  .use(bodyParser.json())
  // Turn on URL-encoded parser for REST services
  .use(bodyParser.urlencoded({ extended: true }));

// Create an in-memory localstorage Feathers service with a default page size of 2 items and a maximum size of 4
app.use('/messages', localstorage({
  storage: storage,
  paginate: {
    default: 2,
    max: 4
  }
}));

// Create a dummy Message
app.service('messages').create({
  text: 'Server message',
  read: false
}).then(function(message) {
  console.log('Created message', message);
});

// Start the server.
var port = 3030;

app.listen(port, function() {
  console.log(`Feathers server listening on port ${port}`);
});

You can run this example with npm start from the cloned repository and going to localhost:3030/messages. You will see the test Message that we created at the end of that file.

Changelog

0.3.0

  • Revert create so that it behaves the same as every other service and doesn't call update.

0.2.0

  • get and find methods were not waiting for store to be ready
  • create will not throw a Conflict error if id exists anymore. Instead it updates more like a cache and localstorage is expected to work.

0.1.0

License

Copyright (c) 2015

Licensed under the MIT license.

Something went wrong with that request. Please try again.