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

.env is not being loaded or picked up in settings #229

Closed
o-on-x opened this issue Nov 7, 2024 · 2 comments
Closed

.env is not being loaded or picked up in settings #229

o-on-x opened this issue Nov 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@o-on-x
Copy link
Contributor

o-on-x commented Nov 7, 2024

process.env is just system settings. the .env wasnt getting added

quick work around solution

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

// Convert import.meta.url to a file path
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log(__dirname, " ", __filename)
// Correctly resolve the path to the .env file in the core package
const envFilePath = path.resolve(__dirname, '../.env'); // Adjusted path to go one level up to the core directory
const envFileContent = fs.readFileSync(envFilePath, 'utf8');

// Function to parse the .env file content into process.env
function parseEnvFileContent(content: string) {
    const lines = content.split('\n').filter(line => {
        const trimmedLine = line.trim();
        // Ignore empty lines and lines starting with #
        return trimmedLine && !trimmedLine.startsWith('#');
    });

    lines.forEach(line => {
        // Remove inline comments
        const cleanLine = line.split('#')[0].trim();
        const [key, value] = cleanLine.split('=');
        if (key && value) {
            process.env[key.trim()] = value.trim();
        }
    });
}

// Parse the .env file content
parseEnvFileContent(envFileContent);

const settings = process.env;
console.log("settings: ", settings);

export default settings;

@o-on-x o-on-x added the bug Something isn't working label Nov 7, 2024
@o-on-x
Copy link
Contributor Author

o-on-x commented Nov 8, 2024

latest push fixed this

@o-on-x
Copy link
Contributor Author

o-on-x commented Nov 8, 2024

closed

@o-on-x o-on-x closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant