Project realized for UC Berkeley Extension Coding Bootcamp
This App allows you to write, save, and delete notes efficiently. The notes are consistent and stored on your local machine for full privacy.
Download the project on your local machine. Make sure you have node installed then at the root of the folder run the command:
npm install
run the commande
node server.js
then visit: http://localhost:3000/
app.delete('/api/notes/:id', (req, res) => {
var deletion = req.params.id
for(var i = 0; i < notes.length; i++) {
if(deletion == notes[i].id) {
notes.splice(i, 1);
break;
}
}
fs.writeFile(path.join(__dirname, 'db/db.json'), JSON.stringify(notes), err => { });
res.redirect('/notes');
});
In this example, I used the splice method to delete the selected note from the JSON object, then stringify it and save it inside the db.json file using fs.