
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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.
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.
Either through cloning with git or by using npm (the recommended way):
npm install env-git # or yarn install env-git
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.
To represent both ways of providing configuration in the usage section, you can update the code examples as follows:
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.
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();
To obtain the GitLab repository access token and information, follow these steps:
To obtain the GitHub repository access token and information, follow these steps:
To obtain the Bitbucket repository access token and information, follow these steps:
FAQs
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.
The npm package env-git receives a total of 1 weekly downloads. As such, env-git popularity was classified as not popular.
We found that env-git demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.