M
M
Marat Shakirov2021-10-22 16:30:13
npm
Marat Shakirov, 2021-10-22 16:30:13

How to add a property to process.env?

Created a .env.local file in the root folder of the project, to which I added API_KEY. I want to refer to it in the component, downloaded via npm dotenv, added the line . I output to the console , but for some reason the value of this property is undefined require('dotenv').config()console.log(process.env.API_KEY)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nam Zanilla, 2021-10-22
@sadsdasdasdsadsadsadsadsa

By default, in my opinion, the .env file is searched, but in the options you can specify the path if you have an arbitrary name, or the file lies in some place where the module cannot find it, let's say path: path.resolve(__dirname, '. env.local')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question