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 usersGET /users/1
β returns the user with ID1
POST /users
β create a new userPATCH /users/1
β update an existing userDELETE /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