I write a nodejs program to call data form API, it is working if I hard code the API key and token.
Hard code the API key and token is working:
let username = "userid"; //--API_USERNAME
let token = "hfdhdfgfdhgs24" //API TOKEN;
let auth = btoa(`${username}:${token}`);
I store the key and token into .env file , however cannot get the data when calling the API.
It seems cannot read the value from the .env file, would anyone can help?
//.env file
API_USERNAME=userid
//.js code
import dotenv from "dotenv"
dotenv.config();
`var myHeaders = new Headers();
let token = "hfdhdfgfdhgs24" //API TOKEN;
let auth = btoa(`${process.env.API_USERNAME}:${token}`);