Search code examples
node.jsvariablesclient

Change variable that lives on the nodejs server from client side


I have a question, lets say that i have a variable that lives on the nodejs server called: Var optionOne = "Yes"

And i want to change that variable from the client side by a button press. How would i handle that?, because obviously document.getElementById("myBtn").addEventListener("click", change) wont work.

Any help would be appreciated.


Solution

  • Once Node is just for server side, after you do something like this document.getElementById("myBtn").addEventListener("click", change) you will need to send this information from the client to the server side.

    like this

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send(document.getElementById("myBtn").value);