Commit 851d1c8a authored by Vadim's avatar Vadim

Конец занятия 74

parent 068942e8
[{"title":"Новый продукт2","price":100,"description":"Product description"},{"title":"Новый продукт3","price":100,"description":"Product description"}]
\ No newline at end of file
const fs = require('fs');
const fileName = './db/db.json';
let data = [];
module.exports = {
init() {
try {
const fileContents = fs.readFileSync(fileName, 'utf-8');
data = JSON.parse(fileContents);
}catch (e) {
data = []
}
},
getItems() {
return data;
},
addItem(item) {
data.push(item);
this.save();
},
save() {
fs.writeFileSync(fileName, JSON.stringify(data));
}
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment