After running this code, I noticed that even when inputting a different userId, it still ends up overwriting the existing user instead of adding a new one as intended.
const user = userId;
const userObj = {[user]:valueX};
words.users = userObj;
fs.writeFileSync('words.json', JSON.stringify(words,null,2), finished);
The input is taken from here (readline-sync)
let userId = input.question('Enter yourUserId: ');
And of course, I am reading the file first
let words = JSON.parse(fs.readFileSync('words.json'));