What is @probe.gl/env?
@probe.gl/env is a utility library designed to help with environment detection and configuration in JavaScript applications. It provides tools to detect the runtime environment, manage environment variables, and handle logging and debugging.
What are @probe.gl/env's main functionalities?
Environment Detection
This feature allows you to detect whether your code is running in a browser or Node.js environment. The code sample demonstrates how to use the `isBrowser` and `isNode` functions to log the current environment.
const { isBrowser, isNode } = require('@probe.gl/env');
if (isBrowser) {
console.log('Running in a browser environment');
} else if (isNode) {
console.log('Running in a Node.js environment');
}
Environment Variables
This feature helps you manage environment variables. The `getEnv` function retrieves the value of an environment variable, with an optional default value if the variable is not set. The code sample shows how to get the `API_URL` environment variable.
const { getEnv } = require('@probe.gl/env');
const apiUrl = getEnv('API_URL', 'https://default.api.url');
console.log(`API URL: ${apiUrl}`);
Logging and Debugging
This feature provides logging and debugging utilities. The `log` object offers methods like `info`, `warn`, and `error` to log messages at different levels. The code sample demonstrates how to use these logging methods.
const { log } = require('@probe.gl/env');
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
Other packages similar to @probe.gl/env
dotenv
dotenv is a popular package for loading environment variables from a `.env` file into `process.env`. It is widely used for managing environment-specific configurations in Node.js applications. Unlike @probe.gl/env, dotenv focuses solely on environment variable management and does not provide environment detection or logging utilities.
env-var
env-var is a package for retrieving and validating environment variables. It provides a more robust API for handling environment variables compared to @probe.gl/env. However, it does not include features for environment detection or logging.
winston
winston is a versatile logging library for Node.js. It offers extensive logging capabilities, including multiple transports, log levels, and formatting options. While winston excels in logging, it does not provide environment detection or environment variable management like @probe.gl/env.
@probe.gl/env
JavaScript environment detection for browser and Node
probe.gl is a collection of logging, instrumentation, bench-marking and test tools for JavaScript applications.
For documentation please visit the website.