Coder Social home page Coder Social logo

json-server-init's Introduction

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 - 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 render 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 to generate for this collection. For example, users 10 will generate collection "users" with 10 records in it, sesstions 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 should 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, refere entire list for possible values.

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

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

Add another

You can add as many collections as necessary, after fields prompt there is a confirmation if more collections needs 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 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

{
    "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

json-server-init's People

Contributors

dfsq avatar typicode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.