[GH-ISSUE #1629] Helper Module Request- .env environment variable check #515

Closed
opened 2026-03-16 15:49:18 +03:00 by kerem · 3 comments
Owner

Originally created by @bhavukkalra on GitHub (May 6, 2021).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/1629

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 ?

Originally created by @bhavukkalra on GitHub (May 6, 2021). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/1629 Is there a possibility to add Helper Module to the [Helper's Directory](https://github.com/hoppscotch/hoppscotch/tree/main/helpers) 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 ```javascript 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 ?
kerem 2026-03-16 15:49:18 +03:00
Author
Owner

@liyasthomas commented on GitHub (May 6, 2021):

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

<!-- gh-comment-id:833361170 --> @liyasthomas commented on GitHub (May 6, 2021): @AndrewBastin what do you think? I can't find any implications with this flexibility in Hoppscotch as of now.
Author
Owner

@AndrewBastin commented on GitHub (May 6, 2021):

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 ?

<!-- gh-comment-id:833516728 --> @AndrewBastin commented on GitHub (May 6, 2021): 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 ?
Author
Owner

@bhavukkalra commented on GitHub (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

<!-- gh-comment-id:834097027 --> @bhavukkalra commented on GitHub (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](https://github.com/hoppscotch/hoppscotch/blob/main/.env.example) 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#515
No description provided.