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)

In your terminal, run: npx json-server --watch database.json

: For larger projects, consider libraries like lowdb , which provide a safer API for interacting with local JSON files. typicode/lowdb: Simple and fast JSON database - GitHub

Database.json -

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)

In your terminal, run: npx json-server --watch database.json database.json

: For larger projects, consider libraries like lowdb , which provide a safer API for interacting with local JSON files. typicode/lowdb: Simple and fast JSON database - GitHub { method: 'POST'

Remove Ads | Report This Ad