Git Product home page Git Product logo

json-server's Introduction

Fake JSON Server

If you want to use full fake NoSQL datebase using json-server that can be used in development purpose as a simpler database for smaller applications. You can use this repo for that.

How to create your own fake REST API's using json server

1 . Clone this repo on your computer.

$ git clone https://github.com/akamit21/json-server.git

2 . Add your own content to db.json and then commit your changes to git.

this example will create /users and /posts route , each resource will have their own data depending on what are adding o it. In the second example you can see that I have added {id, name and email} to users array and {id, title and content} to posts array. In both cases id will auto increment!

{
  "users": [],
  "posts": []
}
{
  "users": [
    {
      "id": 1,
      "name": "Full name!",
      "email": "[email protected]"
    }
  ],
  "posts": [
    {
      "id": 0,
      "title": "First post!",
      "content": "My first content!"
    }
  ]
}

In both cases data's are dummy you can have data of your own choice.


Deploying it to Heroku

Heroku is a free hosting service for hosting small projects. Easy setup and deploy from the command line via git.


Install Heroku

1 . Create your server

2 . Create an account on
https://heroku.com

3 . Install the Heroku CLI on your computer:
https://devcenter.heroku.com/articles/heroku-cli

4 . Connect the Heroku CLI to your account by writing the following command in your terminal and follow the instructions on the command line:

heroku login

5 . Then create a remote heroku project, kinda like creating a git repository on GitHub. This will create a project on Heroku with a random name. If you want to name your app you have to supply your own name like heroku create project-name:

heroku create `project name`

6 . Open your project folder by writing the following command in your terminal and follow the instructions on the command line:

cd `project name`

7 . Push your app to Heroku (you will see a wall of code)

git push heroku master

8 . Visit your newly create app by opening it via heroku:

heroku open

9 . For debugging if something went wrong:

heroku logs --tail

Run it locally on your PC

Heroku will look for a startup-script, this is by default npm start so make sure you have that in your package.json (assuming your script is called server.js):

1 . Clone repository

$ git clone https://github.com/akamit21/json-server.git
$ cd json-server

2 . Run npm install npm install will install all modules listed as dependencies in package.json file.

$ npm install

3 . Run npm run start It will run application in http://localhost:3000

$ npm run start
$ npm run dev `if you want to use nodemon`
 "scripts": {
    "start" : "node server.js",
    "dev" : "nodemon server.js"
 }

4 . You also have to make changes to the port, you can't hardcode a dev-port.

const port = process.env.PORT || port_number;

Contribute

Contributions are always welcome!

Amit Kumar

Twitter : @Amitaldo

Credit : Jesper Orb

json-server's People

Contributors

akamit21 avatar

Watchers

James Cloos 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.