My scenario is that I am trying to add headers to a node request object. But I'm hung up on just creating the headers array.
let headers = [];
let options = {
url: this.baseUrl + appconst.route.postMessage
};
if (token) {
console.log(appconst.headers.authToken); // no problem here
let authTokenHeader = { appconst.headers.authToken: token.toBase64() }; // throws
headers.push(authTokenHeader);
}
if (msg) {
headers.push({ 'content-type': 'application/json' });
options.body = JSON.stringify(msg);
}
The 'throws' line is giving...
let authTokenHeader = { appconst.headers.authToken: token.toBase64() };
^
SyntaxError: Unexpected token .
Can you please help me understand what is going on here? I am very confused because the "const.headers.authToken" is defined and the line above it works fine. Yes, I am very new to JavaScript.