1.0.29 • Published 3 years ago

jsonbackend v1.0.29

Weekly downloads
70
License
MIT
Repository
-
Last release
3 years ago

Initializing object database server

Live demo of this service: https://jsonbackendserver.herokuapp.com/

const jsonbackend = require("jsonbackend");
jsonbackend.listen();  // This would run the endpoint on port 3000.
//or you can specify custom port i.e., `jsonbackend.listen(4000)` would have run the database endpoint @ 4000 port.

Usage of db's endpoint from frontend with axios

You can create a express server that can act as a reliable 'object database server'. So you might be wondering what could a 'object database server' which would behave in a manner that you can directly post the data to the endpoint or use a $partial property to send partial data to be updated in the existing data in the database. For e.g.,

1. Put data in database like -

let dataToPost = {
  cars: 200,
  bikes: 400,
  ships: {
    big: true,
    small: ['rem', 'bem', 'tem']
  }
}

let {data} = await axios.post("https://localhost:3000/foo", dataToPost)

would just save this object to file foo.json and you can see it directly in the mydbs directory.

1.1 After saving you can fetch the data with post request, e.g

let {data} = await axios.post("https://localhost:3000/foo")

2. Also, you can update a particular property in the json database via sending a post request like -

let dataToPost = {
  $partial: {
    ships: "Cool",
    kicks: 200
  }
}
let {data} = await axios.post("https://localhost:3000/foo", dataToPost)

would just alter the property of ships in the database(db.json), so our final database state would look like:

let dataToPost = {
  cars: 200,
  bikes: 400,
  ships: "Cool",
  kicks: 200
}
let {data} = await axios.post("https://localhost:3000/foo", dataToPost)

Author's Resources

  • Nodemon faq's : Excluding watch files from nodemon.
  • This command/script works too for excluding watch files for nodemon - "start2": "nodemon --ignore mydb.json -q index.js".
1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago