Database.json
Database.json
If you aren't using a server and just want to append data to the file locally using Node.js: javascript
If you want to treat database.json like a real REST API, json-server is the standard choice. database.json
: Always include a unique id for each post so you can find or delete it later. If you aren't using a server and just
const fs = require('fs'); const newPost = { id: Date.now(), title: "Direct Write", content: "Added via fs module" }; // 1. Read the existing file const data = fs.readFileSync('database.json'); const db = JSON.parse(data); // 2. Add the new post db.posts.push(newPost); // 3. Write it back fs.writeFileSync('database.json', JSON.stringify(db, null, 2)); Use code with caution. Copied to clipboard 3. Using Python Python is often used for simple JSON "databases": const newPost = { id: Date.now()