Fork on GitHub PigguFortune.js

Fortune.js is a library for managing structured data in Node.js and web browsers. It consists of a data abstraction layer and networking functions.

The latest version is 4.0.3, get it from npm, or download here:

npm install fortune --save


Fortune.js implements a data abstraction layer, and also includes networking functions, specific for Node.js and web browsers. There are a variety of use cases for Fortune.js, for example:


The only required input is record type definitions. Here's a model of a basic micro-blogging service:

const fortune = require('fortune')

const store = fortune({
  user: {
    name: { type: String },

    // Following and followers are inversely related (many-to-many).
    following: { link: 'user', inverse: 'followers', isArray: true },
    followers: { link: 'user', inverse: 'following', isArray: true },

    // Many-to-one relationship of user posts to post author.
    posts: { link: 'post', inverse: 'author', isArray: true }
  post: {
    message: { type: String },

    // One-to-many relationship of post author to user posts.
    author: { link: 'user', inverse: 'posts' }

By default, the data is persisted in memory. There are adapters for databases such as MongoDB, Postgres, and NeDB. To make a request internally:

  type: 'user',
  method: 'create',
  payload: [ { name: 'John Doe' }, { name: 'Jane Doe' } ]

The first call to request will trigger a connection to the data store, and it returns the result as a Promise.

Then let's add a HTTP server:

const http = require('http')

// The `` helper function returns a listener function which
// does content negotiation, and maps the internal response to a HTTP response.
const server = http.createServer(

store.connect().then(() => server.listen(1337))

This yields an ad hoc JSON over HTTP API, as well as a HTML interface for humans. There are serializers for Micro API (JSON-LD) and JSON API, which also accept HTTP parameters. In addition, Fortune.js implements a wire protocol based on WebSocket and MessagePack.

See the plugins page for more details.

Features and Non-Features#


Fortune.js is written in ECMAScript 5.1 syntax, with some ECMAScript 6 additions.