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 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-rest-serve

v1.2.2

Published

To serve a json data file as a REST endpoint.

Readme

JSON REST Serve

A NodeJs tool to serve a JSON data as REST end points.

Install

$ npm install json-rest-serve

##Requirements

  • The JSON data should be an array of objects.
  • Each object (data item) should be identifiable with a primary key property.
  • The primary key should be either string or integer.
  • The data item can have nested objects within it.
  • The added resource should have atleast one data item in its data array.
  • The tool uses the first data item to understand the structure of it. It then uses this information to enforce the same structure during the POST and PUT operations.

How to use

Steps:

  • Add one or more resources that you want to serve as REST endpoints.
  • After adding, call the serve method with your preferred port number.
  • name, key and data are required to add a resource.
'use strict';

let jsonRestServe = require('json-rest-serve');

jsonRestServe.resource.add({
    root: 'api',
    name: 'employee',
    key: 'id',
    data: require('./data/employee.json'),
    pageSize: 8
});

jsonRestServe.resource.add({
    root: 'static',
    name: 'country',
    key: 'code',
    data: require('./data/country.json'),
    pageSize: 25,
    readOnly: true
});

jsonRestServe.serve(9000);

Outcome

  • REST endpoints for employee such as http://localhost:9000/api/employee, http://localhost:9000/api/employee/:id
  • REST endpoints for country such as http://localhost:9000/static/country, http://localhost:9000/static/country/:code
  • You can do all the REST CRUD operations on employee resource.
  • You can do only read and read all operation on country resource as it is marked as readOnly.
  • You can view the document pages for the added resources at http://localhost:9000/documents/index.html
  • The first data item from each resource's data array can be seen as a sample data in the above document link.
  • Please see the examples directory for the complete code and data.

Options and Parameters

resource.add(options)

Key | Type | Default | Description | --- | --- | --- | --- | root|String|api|Forms the base of rest urls after http://localhost:9000| name|String|Required field|This would be the name of the resource| key|String|Required field|Name of the primary key attribute of the data item.| version|String||This version value would be added to the url. Example: http://localhost:9000/v1/api/employee| data|Array|Required field|An array of objects with a definite primary key| pageSize|Integer|10|Used in get all operation which is paginated.| schema|Object|The tool generates a schema when not provided|You can provide a robust schema for your JSON data item. The schema should adhere to draft-04 of json-schema.org|

serve(portNumber, morganLogFormat)

Parameter | Type | Default | Description | --- | --- | --- | --- | portNumber|Integer|9000|Port number of the REST endpoints| morganLogFormat|String|dev|Takes pre-defined formats provided by Morgan logging tool such as combined, common, dev, short, tiny, etc.|

Features

  • Can serve any array of objects JSON data with any structure and with any primary key.
  • Can add as many resources before calling serve method.
  • Does not update the json file for PUT/POST/DELETE operations. All the changes you make through the REST calls will be lost once you terminate the process.
  • CORS enabled
  • Can be used as a developer tool and not for any production deployment.
  • Filter, sort, search and field selection features are available with GET requests. See the generated apidocs (http:/documents/index.html) for more information.

Driven by

  • Primarily powered by Lodash and Restify
  • Supported by other libraries such as Morgan, Ajv and Rimraf.
  • Document site is powered by apidoc.

License

MIT