I'm not able to solve following file Handling problem in NodeJS:I have a file emp.txt that contains employee data in fixed record size in the following format:
EmpID:Name:Dept:Salary
1001:Harry:Sales:23000
1002:Sarita:Accounts:20000
1003:Monika:TechSupport:35000
Read the file. Display sum of salary of all employees
I have tried following code to read file successfully, but not getting logic to solve the exact problem. My code to read File:
var fs = require("fs");
console.log("Going to read file!");
fs.readFile('emp.txt', function(err, data){
if(err){
return console.error(err);
}
console.log(data.toString().split(":"));
console.log("read Successfully");
})
What is the correct logic to read Salary field from emp.txt and calculate it's sum?