Database.json -
: Always include a unique id for each post so you can find or delete it later.
Create a database.json with an initial structure: { "posts": [] } Use code with caution. Copied to clipboard database.json
If you want to treat database.json like a real REST API, json-server is the standard choice. : Always include a unique id for each
fetch('http://localhost:3000/posts', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ title: "My First Post", content: "This is some data saved to database.json!" }), }) .then(response => response.json()) .then(data => console.log('Success:', data)); Use code with caution. Copied to clipboard 2. Using Node.js (Direct File Writing) { method: 'POST'
If you aren't using a server and just want to append data to the file locally using Node.js: javascript