I am trying to save my API key as an environment variable, but I don't know how to reach it... I npm installed dotenv, created the file in the root directory, and put the key there. I try to access it in a js file by using process.env.API_KEY but it says that the variable is undefined.
I tried putting require('dotenv').config()
at the top of the file I need the key in, but it gives me an error...
ERROR in ./node_modules/dotenv/lib/main.js 2:13-28
Module not found: Error: Can't resolve 'path' in ...
I think I am either putting it in the wrong file, or I am missing something entirely