var fs require fs var async require node_modules async var info field1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fs = require("fs");
var async = require("./node_modules/async")
var info = {
"a": {
"field1": [1222234, 5622278],
"field2": "asdasd"
},
"b": {
"field_a":[1333357, 2468333],
"field_b": 0
}
}
var writeToFile = function(file, data){
return fs.exists(file, function(exists){
if(exists) {
console.log('FILE EXIST! FILE WILL BE DELETED!!!');
fs.unlink(file, function (err) {
if(err) console.log('del err', err)
else console.log('FILE DELETED');
})
} else console.log('FILE NOT EXIST! FILE WILL BE CREATED!!!');
var stringToWrite = "N_CUST\n" + data.join("\n");
fs.writeFile(file, stringToWrite, function (err) {
if (err) console.log("write err", err);
else console.log('FILE CREATED!')
})
});
}
async.series([
writeToFile("text.txt", info.b.field_a),
writeToFile("text1.txt", info.a.field1),
], function (err, result) {
if (err) console.log("TOTAL RESULT - ERR:", err)
else console.log("ALL FILES SAVED!!!")
});