.controller("addContact",function($scope,$http){ $scope.add=function(){
var myContact={
"department":$scope.department,
"name":$scope.name,
"model":$scope.model,
"year":$scope.year,
"price":$scope.price
};
console.log(myContact);
$http.post("/addItem",myContact)
.then(function(response){
console.log(response);
});
public.post('/addItem',function(request,response){ console.log("incoming data=" +request.body);
fs.readFile(__dirname + "/public/items.json", 'utf-8', function(err, data) {
console.log('file data' + data);
var fileJsonData = data;
var newContact = request.body;
newContact.id = fileJsonData.items.length + 1;
console.log("newContact=" + JSON.stringify(newContact));
fileJsonData.items.push(newContact);
var stringFile = JSON.stringify(fileJsonData);
fs.writeFile(__dirname + "/items.json", stringFile);
response.send(stringFile);
});
});