Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

env-git

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-git

The project is a library designed to facilitate the retrieval and parsing of environment variables from various hosting platforms. It provides functions to extract environment variables from environment files stored on GitLab, GitHub, and Bitbucket.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-88.24%
Maintainers
1
Weekly downloads
 
Created
Source

env-git

Description

The project is a library designed to facilitate the retrieval and parsing of environment variables from various hosting platforms. It provides functions to extract environment variables from environment files stored on GitLab, GitHub, and Bitbucket.

Overall, this library simplifies the process of retrieving and parsing environment variables from environment files stored on different hosting platforms, making it easier to manage and utilize those variables within an application.

Installation

Either through cloning with git or by using npm (the recommended way):

npm install env-git # or yarn install env-git

Parameters

  • hostingPlatform (string): The hosting platform where the repository is hosted. It accepts three possible values: "gitlab", "github", or "bitbucket". This parameter determines the platform-specific logic for retrieving the environment file.

  • config (object): Additional configuration options for the hosting platform. This parameter is optional and can be used to provide specific configuration settings based on the hosting platform.

Usage

To represent both ways of providing configuration in the usage section, you can update the code examples as follows:

1. Using a Environment Variable

The library supports configuration using various file formats such as .env, .json, or .yaml. By providing a configuration file in one of these formats.

To utilize the env-git library, you can create a .env file in your repository. The .env file should contain the environment variables you want to retrieve and use in your application.

Here's an example of a .env file:


GIT_ENV_PLATFORM=gitlab
GIT_ENV_ACCESS_TOKEN=your-access-token
GIT_ENV_REPO=your-repository /* project-id for gitlab, repo-slug for bitbucket */ 
GIT_ENV_BRANCH=your-repo-branch
GIT_ENV_FILE_PATH=.env

GIT_ENV_OWNER=your-github-username  # Only for GitHub
GIT_ENV_HOST_URL=your-gitlab-host-url  # Only for GitLab
GIT_ENV_WORKSPACE=your-bitbucket-workspace  # Only for Bitbucket

Note: Assign the appropriate values to each environment variable without changing the key names. This configuration enables the library to fetch and load the environment variables from the corresponding hosting platform based on the provided values.

Once you have the .env file in your repository, you can use the loadEnvFromFile function to load the environment variables directly from the file:

/* Import the required function from the library */
import GitENV, { PLATFORM } from "env-git";

async function main() {
    const readENV = new GitENV();
    /* This function is used to fetch environment variables from a repository 
    hosted on different platforms and load them into the process.env. */
    await readENV.loadEnv();

   /* This function is used to fetch environment variables from a repository hosted 
   on different platforms and returns them as an object but without directly 
   modifying the process.env. */
  // await readENV.fetchEnv();
}

main();

Users can choose the approach that suits their needs and provide the necessary configuration accordingly.

2. Using Function Arguments

The library provides two functions, loadEnv and fetchEnv, that allow you to retrieve and load environment variables using function arguments.

Here an example demonstrates how to directly specify the configuration using function arguments, allowing users to provide the necessary details.

/* Import the required functions and constants from the library */
import GitENV, { PLATFORM } from "env-git";


const platform = PLATFORM.GITHUB;
const config = { 
    access_token: "your-access-token",
    repository: "your-repository", /* project-id for gitlab, repo-slug for bitbucket */ 
    repo_branch: "your-repo-branch",
    file_path: ".env",
    /* Additional platform-specific configuration options */
    host_url: "your-gitlab-host-url", # Only for GitHub
    owner: "your-github-username", # Only for GitLab
    workspace: "your-bitbucket-workspace", # Only for Bitbucket
}


async function main() {
    const readENV = new GitENV({platform, config});
    /* This function is used to fetch environment variables from a repository 
    hosted on different platforms and load them into the process.env. */
    await readENV.loadEnv();

  /* This function is used to fetch environment variables from a repository hosted 
  on different platforms and returns them as an object but without directly 
  modifying the process.env. */
  // await readENV.fetchEnv();
}

main();

Obtaining Repository Access Token Platform Wise

GitLab

To obtain the GitLab repository access token and information, follow these steps:

GitHub

To obtain the GitHub repository access token and information, follow these steps:

Bitbucket

To obtain the Bitbucket repository access token and information, follow these steps:

FAQs

Package last updated on 21 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc