npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-api-mock-server

v0.1.2

Published

A JSON-API mock server.

Readme

JsonAPI Mock Server

A simple json-api validated mock server.

Installation

yarn add json-api-mock-server

Setup

var mountEndpoints = require('json-api-mock-server');

mountEndpoints(app, config);

app is expected to be an express application instance.

json-api-mock-server expects to find:

  • models at <project>/server/models/*.js
  • scenarios at <project>/server/scenarios/*.js

It will gracefully warn when these aren't found.

Config Settings (with defaults)

{
  logApiRequests: true,
  logApiResponses: true,
  serializer: null,
  scenario: 'default'
  apiNamespace: 'api'
}

Use with ember-cli

In server/index.js (add this file if not present):

/*jshint node:true*/
var mountEndpoints = require('json-api-mock-server');
var config = {
   logApiRequests: true,
   logApiResponses: true,
   serializer: null,
   scenario: 'default'
   apiNamespace: 'api'
 };
 
module.exports = function(app) {
  mountEndpoints(app, config);
};

You will put the models and scenarios directories inside of this server/ directory.

Models

Creating a simple model (no relationships): example server/models/foo.js

var faker = require('faker');
var props = require('json-api-mock-server/lib/store/props');
var between = require('json-api-mock-server/lib/utils/between');
var attr = props.attr;

module.exports = {
  title: attr('string', { defaultValue: function() { return faker.lorem.words(between(3, 5)); }}),
  bar: one('bar', { inverse: 'foo', defaultValue: false }),
};

Creating a model foowith a one-to-(one|none|many) relationship with another model bar

var faker = require('faker');
var props = require('json-api-mock-server/lib/store/props');
var between = require('json-api-mock-server/lib/utils/between');
var attr = props.attr;
var one = props.one;

module.exports = {
  title: attr('string', { defaultValue: function() { return faker.lorem.words(between(3, 5)); }}),
  bar: one('bar', { inverse: 'foo', defaultValue: false }),
};
  • Omit inverse or set it to a false-y value for one-to-none behavior.
  • setting defaultValue to true will cause a related model to be created while seeding the database. Setting it to false will cause there to be no related model for this record.
  • defaultValue can also be a function that returns true or false.

Creating a model foowith a many-to-(one|none|many) relationship with another model bar

var faker = require('faker');
var props = require('json-api-mock-server/lib/store/props');
var between = require('json-api-mock-server/lib/utils/between');
var attr = props.attr;
var many = props.many;

module.exports = {
  title: attr('string', { defaultValue: function() { return faker.lorem.words(between(3, 5)); }}),
  bars: many('bar', { inverse: 'foo', defaultValue: function() { return between(0, 3); }),
};
  • defaultValue can be numeric
  • the number you set defaultValue to or which defaultValue() returns represents the total number of relationships to seed for the related model. e.g. returning 4 will cause 4 bar records to be instantiated.

Scenarios

Example server/scenarios/default.js

module.exports = function(store) {
  store.seed('user', 10);
  store.seed('contacts', 200);
};
  • the count passed to seed is a minimum to create, additional instances may be created during the seeding of the relationships of other record types e.g. if user has contacts and defaultValue on model user is 5, the total number of contacts generated is 5 * 10 + 200 = 250.