parse-google-env-credentials
v1.0.9
Published
Verify if the google credentials are correctly defined on your env and return the values of them to use in ExpressJs or NestJS
Downloads
9
Maintainers
Readme
The Problem 📋
In the cases that we want to use the google functionality, we need to use a configuration file in JSON format but this is an unsecured method to expose our google credentials into our project
The Solution 💡
So, instead of using this file, this configuration could be saved into an environment variable, and nodejs-utils
is the charge to search this variable and validate if first the variable was set correctly, second: validate if the content of the variable was a valid and third convert to a valid JSON type from a string. Also, this library was created with another purpose, to use for setting the logging for the current app using Pino with Pino-http so if you using an ExpressJs or a NestJs project this configure the logger for the corresponding type of project.
Getting Started 🏁
Installation ⚙️
This module is distributed via npm which is bundled with node and
should be installed as one of your project's Dependencies
:
npm install --save nodejs-utils
or
for installation via yarn
yarn add nodejs-utils
Variables 📫
You need to set into your project these environment variables:
Required
- NODE_ENV
Required only in production stage
- GOOGLE_APPLICATION_CREDENTIALS
- LOGGER_NAME
Note: The NODE_ENV variable is in the case that you are on the development you need to put development
and on production should be production
this is because in development stage we don't need to logger on Google cloud and in the case that you are on development
the other variables GOOGLE_APPLICATION_CREDENTIALS
and LOGGER_NAME
it will be only required on production stage.
Usage 🛠
You must need to install pino pino-pretty and pino-stackdriver
yarn add pino pino-pretty pino-stackdriver
or
npm install --save pino pino-pretty pino-stackdriver
Express
Into your logger file or wherever that you configure into your project, you must only import ExpressLogger and declare to use the logger:
import { ExpressLogger } from 'nodejs-utils'
const logger = ExpressLogger()
logger.info('...')
NestJs
In the case that you project is on NestJs you need to install the above library:
yarn add pino nestjs-pino
or
npm install --save pino nestjs-pino
Into your app.module.ts
file you should set this configuration:
import { LoggerModule } from 'nestjs-pino'
import { NestJsLogger } from 'nodejs-utils'
@Module({
imports: [
LoggerModule.forRoot(NestJsLogger()),
...
],
controllers: [],
providers: [],
})
Also into main.ts
:
import { Logger } from 'nestjs-pino'
async function bootstrap() {
...
app.useLogger(app.get(Logger))
...
}
Resume 🧾
That's all now you can start to use this library. Happy Coding 👩💻👨💻🧑💻