Home Blog FAQs Download

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)

: JSON requires double quotes for keys and string values; single quotes will cause an error. database.json

You can now send a POST request to http://localhost:3000/posts using fetch in JavaScript: javascript { method: 'POST'