i have a problem when i want send data from Express to Angular I get error:
SynatxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
File: controller.client.js
$scope.getData = function() {
$http.get('http://localhost:3000/getData').then(function(response) {
alert('good: ');
console.log(JSON.parse(response));
}, function(error) {
alert('Error: ');
console.log("error: ");
console.log(error);
});
}
File: server.controller.js
exports.getData = function(req, res) {
var data = {
"name": "kacper",
"age": 12
};
console.log('getData function: ');
console.log(data);
res.json(data);
}
File server.routes.js
app.get('/getData', index.getData);
and always in my response is error:
SynatxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
how to fix that?