Answer the question
In order to leave comments, you need to log in
Why does the Unexpected end of JSON input error occur?
There is a method:
postJson(data){
return fetch('/todo.json', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(function(response) {
console.info('fetch()', response);
return response;
});
},
this.postJson(this.todos)
.then(()=>{
console.log(this.todos)
})
const express = require('express');
const fs = require("fs");
const app = express();
app.use('/', express.static('dist'));
app.post('/todo.json', (req, res) => {
fs.watchFile('/todo.json', req, (err)=>{
throw err
})
res.end();
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listen on port ${port}...`));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question