Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper Module Request- .env environment variable check #1629

Closed
bhavukkalra opened this issue May 6, 2021 · 3 comments
Closed

Helper Module Request- .env environment variable check #1629

bhavukkalra opened this issue May 6, 2021 · 3 comments
Labels
discussion Talking over coding

Comments

@bhavukkalra
Copy link

Is there a possibility to add Helper Module to the Helper's Directory which checks the current environment upon which the work is being done.

The env file could have a variable APP_ENV , which could take values "production", "development", "undefined"(If Nothing is provided)

The code for the test and configuring the .env path could look something like this(The file will reside in the helpers directory, which could improve the quality of life for local Development)

./helpers/envHandler.js

import dotenv from 'dotenv'
dotenv.config({ path: `${__dirname}/.env` })

const env = process.env.APP_ENV
console.log(`Testing for: ${env}`)
try {
  switch (env) {
    case 'undefined':
      Error(
        'Environment undefined, if local in terminal: export APP_ENV=development'
      )
      break
    case 'development':
      console.log('SAFE: The App is running in development enviroment')
      break
    case 'production':
      console.log('ALERT: The App is running in Production Enviroment')
      break
    default:
      Error('Unrecognized Environment')
  }
} catch (err) {
  Error('Error trying to run file')
}

Does it add any value to the current Repository/Architecture ?

@liyasthomas
Copy link
Member

@AndrewBastin what do you think? I can't find any implications with this flexibility in Hoppscotch as of now.

@liyasthomas liyasthomas added the discussion Talking over coding label May 6, 2021
@AndrewBastin
Copy link
Member

Umm, we already have process.env.CONTEXT exposed to the app which allows you to check whether the app is running on dev mode or production.

If that is not what you meant ? Can you elaborate more ?

@bhavukkalra
Copy link
Author

bhavukkalra commented May 7, 2021

I actually was trying to reproduce the development environment on my local machine and was following the .env.example for entering my own firebase credentials, which I did and got the app running but I seem to be having difficulties finding this CONTEXT variable in the .env.example file in the root directory as it didn't specified the usage of the CONTEXT variable. Am i overlooking something here?

This issue can be closed as @AndrewBastin explained earlier, this variable is already already there.

EDIT - Just got to know that context is a variable injected by Nuxt in to the whole to use .env variables defined on server side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Talking over coding
Projects
None yet
Development

No branches or pull requests

3 participants