When I was trying to add secure API keys in the .env file, I got this error:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-RapidAPI-Host"
at ClientRequest.setHeader (node:_http_outgoing:579:3)
at new ClientRequest (node:_http_client:256:14)
at Object.request (node:https:353:10)
Below is my code:
const axios = require("axios");
const BASE_URL = `https://mashape-community-urban-dictionary.p.rapidapi.com`
module.exports = {
getCompatibility: (yourSearch) => axios({
method:"GET",
url : BASE_URL + `/define`,
headers: {
'X-RapidAPI-Host': process.env.rapidapi_host,
'X-RapidAPI-Key': process.env.Rrapidapi_key
},
params: {
term: yourSearch
}
})
}
My env file:
rapidapi_host={my secure host}
rapidapi_key={my secure key}
Can anyone explain why that is happening?
For me I solved this error just by putting the file extension in the import.
For example, instead of writing
import { file } from "file"
, I wroteimport { file } from "file.js"
in all files.