How to use push() into array json file when “mouse click”?

I only want to push() the array into the json file when “mouse click”, but when i use it as my code nothing show up. I know the node.js is working and the javascript is also working because i test a little experiment on the node.js before

Website for node.js test

https://www.youtube.com/watch?v=U57kU311-nE

how to fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

Website for javascript and json

https://www.khanacademy.org/computing/computer-programming/programming/arrays/pt/modifying-arrays?

8.5: Saving Data to JSON File with Node.js – Programming with Text

https://www.youtube.com/watch?v=6iZiqQZBQJY?

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Oppai</title>

    <link rel="stylesheet" type="text/css" href="style.css">

    <script src="libraries/p5.min.js"></script>
    <script src="libraries/p5.sound.min.js"></script>
  </head>

  <body>
    <script src="Array+json+node.js"></script>
  </body>
</html>

Array+json+node.js

function setup() {
    createCanvas(400, 400);
  }
  
  function draw() {
    background(220);

//var xPositions = [100, 200];
var fs = require('fs');
const { finished } = require('stream');
var data = fs.readFileSync('JsonFilePath1.json');
var xPositions = JSON.parse(data);
console.log(words);
//^ the new json

var draw = function() {
    if (mouseIsPressed) {
        xPositions.push(mouseX);
    }
    noStroke();
    background(212, 254, 255);
    
    stroke(64, 117, 207);
    fill(196, 33, 255);
    for (var i = 0; i < xPositions.length; i++) { 
        line(xPositions[i], 120, 194, 285);
        ellipse(xPositions[i], 104, 32, 46);
    }

//json write node.js
    var data = JSON.stringify(xPositions, null, 2);
    fs.writeFile('JsonFilePath.json', xPositions, finished);
    
    function finished(err) {
        console.log('all set.');
    }
    //^json write

};

  }
  

JsonFilePath1.json

[100, 200]