| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Generate JSON database for JSON server using Filltext.com as random JSON data source.
$ npm install -g json-server-initPossible options are:
For example, to create "dev.json" schema file:
$ json-server-init create -n dev.jsonCommand produces several prompts.
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.
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.
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
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.
TODO...
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.jsonMIT License © Aliaksandr Astashenkau
| Back | FazBrowse Home | New Git URL |