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 3000Alternatively, add it to your project:
npm install --save-dev bananadband run it with:
npx bananadb --db db.json2. 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 4000Youβ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 /posts4. Try It Out
GET /usersβ returns all usersGET /users/1β returns the user with ID1POST /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