Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't require .env to exist #427

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@

### Edit the .env file

Copy .env.example to .env and fill in the appropriate values
Copy .env.example to .env and fill in the appropriate values.

```
cp .env.example .env
```

Note: .env is optional. If your planning to run multiple distinct agents, you can pass secrets through the character JSON

### Automatically Start Eliza

This will run everything to setup the project and start the bot with the default character.
Expand Down
14 changes: 4 additions & 10 deletions packages/core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,12 @@ export function loadEnvConfig(): Settings {
// Node.js environment: load from .env file
const envPath = findNearestEnvFile();

if (!envPath) {
throw new Error("No .env file found in current or parent directories.");
}

// Load the .env file
const result = config({ path: envPath });
// attempt to Load the .env file into process.env
const result = config(envPath ? { path: envPath } : {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming that config({}) doesn't cause any errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not, I checked


if (result.error) {
throw new Error(`Error loading .env file: ${result.error}`);
if (!result.error) {
console.log(`Loaded .env file from: ${envPath}`);
}

console.log(`Loaded .env file from: ${envPath}`);
return process.env as Settings;
}

Expand Down
Loading