Q: How to receive auth token send by client on node js server? I want to send auth token to node js backend server. This is my client-side index.js file.
auth.onAuthStateChanged(user => {
    if(user!=null){
        auth.currentUser.getIdToken(/* forceRefresh */ true)
        .then((idToken) => {
            // Send token to your backend via HTTPS
            var xhr = new XMLHttpRequest();
            xhr.open('POST', "/" , true);
            xhr.onload = function(){
                if(this.status == 200){
                    xhr.setRequestHeader('authToken', idToken);
                }
            }
            xhr.send();
        })
        .catch(function(error) {
            console.log(error);
        });
    }
})

and with below code I am receiving the token. 
router.post('/', function(req, res) {
  authHeader = req.get('authToken');
  console.log(authHeader);
});

But I am getting the value of authHeader as undefined in the terminal. How can I fix this?

A: You don't need to wait until the XHR request is completed before setting the header. Instead you should set the header before sending the request:
var xhr = new XMLHttpRequest();
xhr.open('POST', "/" , true);
xhr.setRequestHeader('authToken', idToken);
xhr.send();

