Получаю текст книги с клиента, который хочу хранить в базе данных:
profileDownWritingForm.addEventListener('submit', () => {
const file = document.querySelector('.profile__down-writing-form-book').files[0];
const reader = new FileReader();
reader.readAsText(file);
reader.onload = function() {
const textBook = reader.result;
const URL = window.location.href.split('/');
const ID = URL[URL.length-1];
fetch(`/profile/${ID}/book`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(textBook)
})
}
reader.onerror = function() {
console.log(reader.error);
}
})
Как получить этот текст на сервере?
router.post('/profile/:id/book', async(req, res) => {
try {
// code
} catch (e) {
console.log(e.message);
}
})