1 | initial version |
There are a few ways to establish environment variables in node, here's one approach:
.env
in the root directory of your project..env
file: GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json
. Replace path/to/credentials.json
with the actual path to your JSON credentials file.dotenv
package by running npm install dotenv
in your terminal or command prompt.GOOGLE_APPLICATION_CREDENTIALS
: require('dotenv').config()
.process.env
object to access the GOOGLE_APPLICATION_CREDENTIALS
variable in your code.For example:
require('dotenv').config()
const credentials = require(process.env.GOOGLE_APPLICATION_CREDENTIALS)
// Use the credentials object in your code