# Environment — the app's own variables

> C#'s `System.Environment`, answering with the APP's values and never the host's: `GetEnvironmentVariable(name)` reads the app's own `app.Config` settings for the mode it runs in, plus `DOTNET_ENVIRONMENT` / `ASPNETCORE_ENVIRONMENT` ("Development" or "Production"); any other name is null. `Environment.NewLine` is "\n". In a server function, in the browser and inside a query alike.

<!-- id: stdlib-environment · area: stdlib · stability: stable · html: https://osysharp.com/reference/stdlib/environment/ -->

## Summary        {#summary}
**`Environment`** is C#'s `System.Environment`, but an app is not a process on a machine it owns, so it answers with
the app's OWN values. `GetEnvironmentVariable` reads the variables the app declared — its [per-environment config (app.Config)](https://osysharp.com/reference/config/app-config/)
settings — and the two the platform gives every app; nothing of the host's environment ever reaches an app.

```osy title="read a setting, and ask whether this is development" test app=stdlib-environment
app.Config = [ new Setting("REGION") { Default = "eu-north" } ];

string Region() => Environment.GetEnvironmentVariable("REGION") ?? "unknown";

bool InDevelopment() => Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";

string[] Lines(string text) => text.Split(Environment.NewLine);
```

## Signature      {#signature}
```osy syntax
string? Environment.GetEnvironmentVariable(string name)   // the app's variable, or null when it has none of that name
string  Environment.NewLine                                // "\n"
```

## Description    {#description}
**What a variable is.** Each `new Setting("NAME")` in `app.Config` is a variable, with the value for the mode the app
is running in — exactly what `Config.NAME` reads, but by a name only known at run time. The platform adds two:
`DOTNET_ENVIRONMENT` and `ASPNETCORE_ENVIRONMENT`, both "Development" on a local platform and "Production" in a
deployment, so the check C# code already makes — `GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development"` —
means what it means in ASP.NET. A setting of the same name wins.

**What it never is.** The host's variables. `PATH`, `HOME` and anything the platform process was started with read
null: an app on a shared host has no business seeing them, and an app's code should not change meaning with the
machine it lands on. A secret is not a variable either — read it as `Secret.NAME` ([declaring secrets (app.Secrets)](https://osysharp.com/reference/config/secrets/)).

**Anywhere.** The same answer in a server function and in the browser (the values ride the page's boot data, as
`Config.X` does), and inside a query, where a variable named by the row (`Environment.GetEnvironmentVariable(j.Name)`)
is looked up by the database.

## Examples       {#examples}
```osy title="the same answers, pinned" run app=stdlib-environment
[Test]
void Environment_is_the_apps_own() {
  Assert.Equal("eu-north", Region());
  Assert.True(InDevelopment());
  Assert.Null(Environment.GetEnvironmentVariable("PATH"));
  Assert.Equal(3, Lines("a\nb\nc").Length);
}
```

## See also       {#see-also}
- [per-environment config (app.Config)](https://osysharp.com/reference/config/app-config/) — declare the variables (`app.Config`) and read one by name (`Config.X`)
- [declaring secrets (app.Secrets)](https://osysharp.com/reference/config/secrets/) — values that must never reach a browser
- [Path — the text of a file path](https://osysharp.com/reference/stdlib/path/) — the text of a file path
