Export variable

2 snippets across 2 stacks — Bash & Linux, JavaScript

SHBash & Linux

Environment Variables

SH · System Info
syntax
env
export VAR=value
printenv VAR
example
env | grep PATH
export DATABASE_URL='postgres://user:pass@db:5432/mydb'
printenv HOME
output
/home/deploy

Note env lists all environment variables. export makes a variable available to child processes. Variables set without export are local to the current shell. printenv retrieves a single variable. Avoid putting secrets in environment variables on shared systems; prefer a secrets manager.

JSJavaScript

Named Exports

JS · Modules
syntax
export const name = value;
export function fn() { ... }
export { a, b, c };
example
// mathUtils.js
export const PI = 3.14159;

export function areaOfCircle(radius) {
  return PI * radius ** 2;
}

export function circumference(radius) {
  return 2 * PI * radius;
}

Note Named exports can be many per module. They must be imported by exact name (or renamed with 'as'). Prefer named exports for better tree-shaking.