Socket
Socket
Sign inDemoInstall

std-env

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    std-env

Runtime agnostic JS utils


Version published
Weekly downloads
4.6M
decreased by-18.09%
Maintainers
1
Install size
25.6 kB
Created
Weekly downloads
 

Package description

What is std-env?

The std-env npm package is designed to help developers easily determine the environment their code is running in. It provides a straightforward way to check if the current environment is development, production, test, or a CI (Continuous Integration) environment. This can be particularly useful for configuring applications differently based on the environment or for including/excluding certain features or outputs based on where the code is running.

What are std-env's main functionalities?

Check if the environment is development

This feature allows you to check if your code is running in a development environment. It's useful for enabling debug logs or development-specific features.

const isDev = require('std-env').isDev;
console.log(isDev); // true if in a development environment

Check if the environment is production

This feature enables you to determine if your application is running in a production environment, which is useful for enabling optimizations or features that should only be available in production.

const isProd = require('std-env').isProd;
console.log(isProd); // true if in a production environment

Check if the environment is test

With this feature, you can easily identify if your code is being executed in a test environment, allowing you to adjust configurations or disable certain functionalities during testing.

const isTest = require('std-env').isTest;
console.log(isTest); // true if in a test environment

Check if running in a CI environment

This feature helps in detecting if your application is running in a CI environment, which can be crucial for configuring CI-specific settings or behaviors.

const isCI = require('std-env').isCI;
console.log(isCI); // true if running in a Continuous Integration environment

Other packages similar to std-env

Changelog

Source

v3.7.0

compare changes

🚀 Enhancements

  • provider: Add railway support (#106)

🩹 Fixes

  • Check bun runtime before node (#107)

💅 Refactors

  • Clarify runtimes and isNode behavior (#108)

🏡 Chore

❤️ Contributors

Readme

Source

std-env

npm npm bundlephobia

Runtime agnostic JS utils

Installation

# Using npm
npm i std-env

# Using pnpm
pnpm i std-env

# Using yarn
yarn add std-env

Usage

// ESM
import { env, isDevelopment, isProduction } from "std-env";

// CommonJS
const { env, isDevelopment, isProduction } = require("std-env");

Flags

  • hasTTY
  • hasWindow
  • isDebug
  • isDevelopment
  • isLinux
  • isMacOS
  • isMinimal
  • isProduction
  • isTest
  • isWindows
  • platform
  • isColorSupported
  • nodeVersion
  • nodeMajorVersion

You can read more about how each flag works from ./src/flags.ts.

Provider Detection

std-env can automatically detect the current runtime provider based on environment variables.

You can use isCI and platform exports to detect it:

import { isCI, provider, providerInfo } from "std-env";

console.log({
  isCI, // true
  provider, // "github_actions"
  providerInfo, // { name: "github_actions", isCI: true }
});

List of well known providers can be found from ./src/providers.ts.

Runtime Detection

std-env can automatically detect the current JavaScript runtime based on global variables, following the WinterCG Runtime Keys proposal:

import { runtime, runtimeInfo } from "std-env";

// "" | "node" | "deno" | "bun" | "workerd" | "lagon" ...
console.log(runtime);

// { name: "node" }
console.log(runtimeInfo);

You can also use individual named exports for each runtime detection:

[!NOTE] When running code in Bun and Deno with Node.js compatibility mode, isNode flag will be also true, indicating running in a Node.js compatible runtime.

Use runtime === "node" if you need strict check for Node.js runtime.

  • isNode
  • isBun
  • isDeno
  • isNetlify
  • isEdgeLight
  • isWorkerd
  • isLagon
  • isFastly

List of well known providers can be found from ./src/runtimes.ts.

Platform-Agnostic env

std-env provides a lightweight proxy to access environment variables in a platform agnostic way.

import { env } from "std-env";

Platform-Agnostic process

std-env provides a lightweight proxy to access process object in a platform agnostic way.

import { process } from "std-env";

License

MIT

FAQs

Last updated on 22 Dec 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc