Skip to Content
🍌 BananaDB 0.1.0 is here β€” spin up a JSON REST API in seconds!
πŸš€ Getting Started

Getting Started

bananaDB makes it easy to spin up a REST API in seconds using just a JSON file.
This guide will walk you through installation, running your first server, and exploring the API.


1. Installation

You don’t need to install bananaDB globally β€” you can run it directly with npx:

npx bananadb --db db.json --port 3000

Alternatively, add it to your project:

npm install --save-dev bananadb

and run it with:

npx bananadb --db db.json

2. Create a Database File

Create a file called db.json in your project root:

{ "users": [ { "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" } ], "posts": [] }

3. Start the Server

Run:

npx bananadb --db db.json --port 4000

You’ll see a startup banner and the available endpoints:

🍌 BananaDB running at: http://localhost:4000 πŸ“‚ Database file: db.json πŸ”Œ Available endpoints: /users GET /users GET /users/:id POST /users PATCH /users/:id DELETE /users/:id /posts GET /posts

4. Try It Out

  • GET /users β†’ returns all users
  • GET /users/1 β†’ returns the user with ID 1
  • POST /users β†’ create a new user
  • PATCH /users/1 β†’ update an existing user
  • DELETE /users/1 β†’ remove a user

Example POST request with curl:

curl -X POST http://localhost:4000/users \\ -H "Content-Type: application/json" \\ -d '{"name": "Charlie"}'

Response:

{ "id": 3, "name": "Charlie" }

5. Hot Reloading

bananaDB watches your db.json file.
When you edit the file, routes and data automatically reload without restarting the server.


6. Command Line Options

  • -p, --port <number> β†’ Port to run the server (default: 3000)
  • -d, --db <file> β†’ JSON file to serve (default: db.json)
  • -w, --watch <file> β†’ Alias for --db (for json-server familiarity)
  • --no-cors β†’ Disable CORS (enabled by default)

πŸ‘‰ Next: Routes

Last updated on