Am taking baby steps with node js. First task, read a delimited file line by line, and spit out the lines that contain the string "imputed".
#!/usr/bin/env node
var Csv = require("csv"),
Fs = require("fs");
var foods = "/../data/sr26";
Csv()
.from.stream(
Fs.createReadStream(__dirname + foods + "/SRC_CD.txt"),
{"delimiter": "^", "quote": "~"}
)
.to(function(data, count) {
console.log(data);
})
.transform(function(row, index, callback) {
//if (row[1].search(/imputed/) != -1) {
process.nextTick(function() {
callback(
null,
row[1].substr(0, 15) + "… " + row[1].search(/imputed/) + "\n"
)
});
//}
});
Prints out
Analytical or d… -1
Calculated or i… 14
Value manufactu… -1
Aggregated data… -1
Assumed zero… -1
Calculated from… -1
Calculated by m… -1
Aggregated data… -1
Manufacturer's … -1
Analytical data… -1
But uncommenting the comparison inside transform results in no output at all. What am I doing wrong?