title: How to trigger a Firebase POST request when a Button is clicked in Node.js / EJS
body: <p><strong>EDIT:</strong></p>
  
  <p>There were actually still some issues. The real problem was actually the Firebase security rules. All was solved here : <a href="https://stackoverflow.com/questions/40408945/how-to-put-a-node-js-variable-inside-my-script-script">How to put a Node.js variable inside my &lt;script&gt;&lt;/script&gt;?</a></p>
  
  <p><strong>QUESTION:</strong></p>
  
  <p>How to trigger a Firebase POST request when "UpvoteButton" or "DownvoteButton" is clicked ?</p>
  
  <hr>
  
  <p><strong>WHAT I TRIED:</strong></p>
  
  <p><strong>UPDATE 4:</strong></p>
  
  <p>I think I am making progress. Find the updated code below. Now I get the error:</p>
  
  <pre><code>SyntaxError: Unexpected token ; in ... while compiling ejs
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>&lt;% include ../partials/header %&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://www.gstatic.com/firebasejs/3.5.0/firebase.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
  &lt;% var config = { %&gt;
  &lt;%    apiKey: "info", %&gt;
  &lt;%    authDomain: "info", %&gt;
  &lt;%    databaseURL: "info", %&gt;
  &lt;%    storageBucket: "info", %&gt;
  &lt;%    messagingSenderId: "info" %&gt;
  &lt;% }; %&gt;
  &lt;% firebase.initializeApp(config); %&gt;
  
  &lt;/script&gt;
  
  &lt;div class ="containerMarginsDetails"&gt;
  
      &lt;h1 class= "detailsTitle"&gt;&lt;%=post.title %&gt;&lt;/h1&gt;
      &lt;div class="row"&gt;
          &lt;img class = "postImg"  src="/images/uploads/&lt;%= post.image %&gt;"&gt;
          &lt;span class="UpvoteButton"&gt; &lt;/span&gt;&lt;span class="DownvoteButton"&gt; &lt;/span&gt; &lt;span class="HP"&gt;&lt;%= post.upvotes - post.downvotes%&gt; HP&lt;/span&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt; 
  
      &lt;% var upvotesRef = firebase.database().ref("posts/section/"+id+"/upvotes"); %&gt;
      &lt;% var downvotesRef = firebase.database().ref("posts/section/"+id+"/downvotes"); %&gt;
  
      $('.UpvoteButton').click(function () {
          &lt;% if(authdata == null) { %&gt;
              window.location.href = "/users/login";
          &lt;% } else { %&gt;
  
              var $this = $(this);
              var $other = $('.DownvoteButton');
  
              if ($this.hasClass("on")) {
                  $this.removeClass("on");
  
                  &lt;%  upvotesRef.transaction(function (upvotes) { %&gt; 
                  &lt;%  if (!upvotes) { %&gt;
                  &lt;%    upvotes = 0; %&gt;
                  &lt;%   } %&gt;
                  &lt;%   upvotes = upvotes - 1; %&gt;
                  &lt;%   return upvotes; %&gt;
                  &lt;%  }); %&gt;
  
              } else if (!$this.hasClass('on') &amp;&amp; $other.hasClass("on")) {
                  $this.addClass('on');
                  $other.removeClass("on");
  
                  &lt;%  upvotesRef.transaction(function (upvotes) { %&gt;
                  &lt;%   if (!upvotes) { %&gt;
                  &lt;%     upvotes = 0; %&gt;
                  &lt;%   } %&gt;
                  &lt;%   upvotes = upvotes + 1; %&gt;
                  &lt;%   return upvotes; %&gt;
                  &lt;% }); %&gt;
  
                  &lt;% downvotesRef.transaction(function (downvotes) { %&gt;
                  &lt;%  if (!upvotes) { %&gt;
                  &lt;%    downvotes = 0; %&gt;
                  &lt;%  } %&gt;
                  &lt;%  downvotes = downvotes - 1; %&gt;
                  &lt;%  return downvotes; %&gt;
                  &lt;% }); %&gt;
  
              } else {
                  $this.addClass('on');
  
                  &lt;% upvotesRef.transaction(function (upvotes) { %&gt;
                  &lt;%  if (!upvotes) { %&gt;
                  &lt;%    upvotes = 0; %&gt;
                  &lt;%  } %&gt;
                  &lt;%  upvotes = upvotes + 1; %&gt;
                  &lt;%  return upvotes; %&gt;
                  &lt;% }); %&gt;
              } 
          &lt;% } %&gt;
      });
  
      $('.DownvoteButton').click(function () {
          &lt;% if(authdata == null) { %&gt;
              window.location.href = "/users/login";
          &lt;% } else { %&gt;
              var $this = $(this);
              var $other = $('.UpvoteButton');
              if ($this.hasClass("on")) {
                  $this.removeClass("on");
              } else if (!$this.hasClass('on') &amp;&amp; $other.hasClass("on")) {
                  $this.addClass('on');
                  $other.removeClass("on");
              } else {
                  $this.addClass('on');
              }
          &lt;% } %&gt;
      });
  
  &lt;/script&gt;
  
  &lt;% include ../partials/footer %&gt;
  </code></pre>