I want to save data to a file in a local file system.
the action what i want to implement is when a button click happens the data should pass to the back end and save the data using fs.
i have a fs code which is working fine.
var fs = require("fs");
var path = "D:\\Temp\\Test.txt";
var data = "Hello";
fs.writeFile(path, data, function(error) {
if (error) {
console.error("write error: " + error.message);
} else {
console.log("Successful Write to " + path);
}
});
then i used above fs code in my developing as below.
angular front end Controller
$scope.sendToBack = function ()
{
var csvData = {
dat: str
};
Event.postDataToCepFs(csvData)
.success(function () {
$scope.status = 'Reading the selected file';
})
.error(function (error) {
$scope.status = 'Unable to insert data: ' ;
});
return str;
};
FrontEnd Service Layer
postDataToCepFs : function(event) {
return $http.post('/api/sendDataToCepFs', event);
$window.location.reload();
},
Backend Route
app.post('/api/sendDataToCepFs', function(req, res) {
var path = "D:\\Test.txt";
fs.writeFile(path, res.body.dat, function(error) {
if (error) {
console.error("write error: " + error.message);
} else {
console.log("Successful Write to " + path);
}
});
});
The above is my approach.but it gives "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"
can anyone help me this this?
Thanks
res.body.dat?