1.0.9 โ€ข Published 2 years ago

parse-google-env-credentials v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago
  1. The Problem
  2. The Solution
  3. Getting Started
    1. Installation
    2. Variables
  4. Usage
    1. Express
    2. NestJs
  5. Resume

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 ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป๐Ÿง‘โ€๐Ÿ’ป

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago