To clarify the title, I'd like to pass in var 1: var 2 as a key-value pair. However, whenever I do this:
fileobject.add = {var 1: var 2}
where fileobject is the name of the array, using ":" automatically changes filename to text.
The rest of my code:
var FileHasher = require("./FileHasher");
if (process.argv.length < 3) {
console.log("Program file and one argument are required for this program.");
process.exit(1);
}
var filename = process.argv[2];
var fs = require('fs');
var data = fs.readFileSync("../sha1.json", "UTF-8"); // read sha1.json contents
var fileobject = JSON.parse(data); // create JS object from file
var file = fs.readFileSync(filename, "UTF-8"); // read file contents
console.log(data); // print all current key-value pairs
fs.createWriteStream("../sha1.json");
var filesha1 = FileHasher(file);
console.log(filesha1);
fileobject.push = (filename: filesha1);
console.log(fileobject);
fs.writeFile("../sha1.json", JSON.stringify(fileobject), function(err) {
if (err) {
return console.log(err);
}
console.log("data saved");
});
For clarification, FileHasher takes whatever input it's given and returns the sha1.
The other issue I'm having is posting the updated information to sha1.json; my current code just posts the same data I took from it back into it, even though console.log(fileobject) shows "pushed: * sha1 value *" alongside the already imported data, but console.log(data) shows only the information that was read from sha1.json, not any of the information I pushed.
Help with this would be much appreciated!