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 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-server-init

v0.2.4

Published

Usefull addition to json-server to generate db.json database schema with random records.

Downloads

17

Readme

JSON Server Init Build Status npm version

Generate JSON database for JSON server using Filltext.com as random JSON data source.

Install

$ npm install -g json-server-init

Commands

  • create - Create new JSON database.
  • collection - Add new collection to existent database file (todo).

Options

Possible options are:

  • --name, -n - Specify name of the database JSON file to create (in case of create command) or use (collection command). Default name if not provided is "db.json".
  • --help, -h - Show help.
  • --version, -v - Show version number.

For example, to create "dev.json" schema file:

$ json-server-init create -n dev.json

Commands overview

create

Command produces several prompts.

Collection prompt

Prompt for collection name and number of rows renders something like this:

> Collection name and number of rows, 5 if omitted (ex: posts 10):

Valid input would be a new collection name with optional number separated by space indicating how many rows should be generated for this collection. For example, users 10 will generate collection "users" with 10 records in it, sessions will result into collection "sessions" with default 5 records, etc.

Fields prompt

After collection name is entered one would need to configure what fields collection should have:

>> What fields should "users" have?
   Comma-separated fieldname:fieldtype pairs (ex: id:index, username:username)

Entry must have specific format: fieldname:fieldtype.

  • fieldname - name of the field, only alpha-numeric characters.
  • fieldtype - type of the data. Corresponds to types filltext generator uses for fields, refer entire list for possible values. Multiple fields concatenation is possible with + operator.

For example, to generate users collection with four fields: id, username, name and age, one could enter this command:

>> What fields should "users" have?
   Comma-separated fieldname:fieldtype pairs (ex: id:index, username:username)
id:index, username:username, name:firstName+lastName, age:numberRange|18,80

Add another

You can add as many collections as necessary: after fields prompt there is a confirmation if more collections need to be created:

> Add another collection? (y/n) n

If "y" is entered flow repeats "Collection prompt" step, otherwise it fetches JSON data and saves it to the file.

collection

TODO...

Example

Here is how typical workflow looks like with create command:

$ json-server-init create
> Collection name and number of rows, 5 if omitted (ex: posts 10): users 2
>> What fields should "users" have?
   Comma-separated fieldname:fieldtype pairs (ex: id:index, username:username)
 id:index, username:username, motto:lorem|5
> Add another collection? (y/n) n
db.json saved.

Above will produce db.json file with content similar to this:

{
    "users": [
        {
            "id": 1,
            "username": "RGershowitz",
            "motto": "curabitur et magna placerat tellus"
        },
        {
            "id": 2,
            "username": "NMuroski",
            "motto": "ante nullam dolor sit placerat"
        }
    ]
}

Now you can start json-server:

$ json-server --watch db.json

License

MIT License © Aliaksandr Astashenkau