I am writing to a js file using protractor as follows :
index.js
var outputFile = '../Actions/data_write.js';
var username = "someusername";
var password = "somepassword";
var fs = require('fs');
var text = "userCredentials : {username : '"+username+"', password : '"+password+"'};";
fs.writeFile(outputFile, text, function(error){
if(error){
console.log(error);
}else{
console.log('data saved to '+outputFile);
}
});
My issue is I am not able to figure out how to write this data at specific location. So like right now the text is written to the entire file by replacing the old content. I want to write it at say at specific location, say I have multiple data with username and password defined in array in this file. I want to write to that specific array.