Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinta365 committed Mar 5, 2024
1 parent 08e9a21 commit cc6ae5f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.env-local
.vscode
test.ts
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,29 @@ await setupEnv({
**Example `.env` file:**

```
# .env-local
MYAPP_DATABASE_HOST=my-database-server
MYAPP_DATABASE_URL=jdbc:mysql://$MYAPP_DATABASE_HOST:3306/my_schema
MYAPP_MESSAGE="Hello, world!"
MYAPP_NOT_EXPAND=Test\$MYAPP_MESSAGE
MYAPP_APP_CONFIG_PATH="config/$MYAPP_DATABASE_URL.properties"
MYAPP_WEB_SERVER_URL=https://$MYAPP_APP_CONFIG_PATH/app
```
Example code to read above `.env-local`-file and console.logging all environmental variables
prefixed with `MYAPP_`

```javascript
import { getAllEnv, setupEnv } from "@cross/env";

await setupEnv({ dotEnv: { enabled: true, path: ".env-local" } });
const allVariables = getAllEnv("MYAPP_");

console.log(allVariables);
// Output of expanded variables ->
// {
// MYAPP_DATABASE_HOST: "my-database-server",
// MYAPP_WEB_SERVER_URL: "https://config/jdbc:mysql://my-database-server:3306/my_schema.properties/app",
// MYAPP_DATABASE_URL: "jdbc:mysql://my-database-server:3306/my_schema",
// MYAPP_APP_CONFIG_PATH: "config/jdbc:mysql://my-database-server:3306/my_schema.properties"
// }
```

## Issues
Expand Down
2 changes: 1 addition & 1 deletion jsr.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cross/env",
"version": "0.1.4",
"version": "0.1.5",
"exports": "./mod.ts"
}

0 comments on commit cc6ae5f

Please sign in to comment.