npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

env-git

v0.0.2

Published

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.

Downloads

32

Readme

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: