Using remoteStorage.js in Node.js

We discussed to only update the Node NPM module after we made sure that it’s actually working with node. So I tried to get the basics working with the current node build.

Before I create any issues on Github for this, I wanted to list the problems I experienced here. Maybe I’m just too stupid and I’m "using it wrong"TM :wink:

Creating a new remoteStorage instance

var RemoteStorage = require('./remotestorage-node');
var remoteStorage = new RemoteStorage();

already fails with the error

TypeError: Cannot read property ‘connected’ of undefined

I traced this back to the WireClient not being created because it needs the XMLHttpRequest.

Requiring the xmlhttprequest module before remotestorage-node fixes that.

var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;

I think that module should be a dependency in the package.json then, doesn’t it?

The next problem I ran into is when trying to configure the remote via

remoteStorage.remote.configure(userAddress, serverURL, storageAPI, token);

I got an error

‘ready’ failed: Sync requires ‘local’ and ‘caching’! undefined

I couldn’t figure this one out yet. My guess is, we need the memory storage, first.

Did anybody use remoteStorage.js in node before? Is there anything else that needs to be done or are these actual bugs?

i think indeed you were probably the first person to use 0.8 in node, they are probably all actual bugs!

I used 0.7.x in node, but not 0.8.x - thanks for testing though, it looks like you are on the right track, and finding bugs :slight_smile:

Welcome to another episode of “Garret’s Node Adventures” :smile:

After dabbling around some more, I managed to get at least the basics working.

What was missing before, was requiring node-localstorage as well and then attach everything to global. So the basic setup looks like this:

var LocalStorage = require('node-localstorage').LocalStorage;
var localStorage = new LocalStorage('./storage');
global.localStorage = localStorage;

var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
global.XMLHttpRequest = XMLHttpRequest;

var RemoteStorage = require('./remotestorage-node');
var remoteStorage = new RemoteStorage();
global.remoteStorage = remoteStorage;

After that I was able to load a module, configure the remote and claim access:


remoteStorage.remote.configure(userAddress, serverURL, storageAPI, token);
remoteStorage.access.claim('bookmarks', 'rw');

Loading all bookmarks works with

  function(bookmarks) {
    console.log('bookmarks', bookmarks);
  function(error) {
    console.log('error', error);

But when I enabled caching with


I got the this error when the first request was made:

ReferenceError: Blob is not defined

pointing to

Also, have you tried PUTing something? That was what didn’t work for me last time.

Yes, I just tried it out. PUTing a bookmark worked fine.

there are no Blobs in node.

It uses Buffers instead, maybe a look at test/unit/wireclient-suite.js in the browser test branch can help you with that.

Even though without further thought and research I can’t explain why the error occures when you turn on caching.

i think this was all fixed in which was merged two months ago. this thread is from November

Yes, all bugs I encountered have been fixed. Forgot to close the topic here.