Skip to content

Commit

Permalink
updating script with finding the .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
recap committed Aug 12, 2024
1 parent 1773ce8 commit 4f458fc
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion server_test/virtual-user-ws.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
const io = require("socket.io-client")
const CryptoJS = require("crypto-js")
require("dotenv").config()
const path = require('path')
const fs = require('fs')
const dotenv = require('dotenv')


// Function to search for .env file in current or parent directory
function findEnvFile() {
let currentDir = process.cwd();

while (true) {
const envPath = path.join(currentDir, '.env');
if (fs.existsSync(envPath)) {
return envPath;
}
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
break; // Reached the root directory
}
currentDir = parentDir;
}

return null; // .env file not found
}

// Load environment variables
const envFilePath = findEnvFile();
if (envFilePath) {
dotenv.config({ path: envFilePath });
} else {
console.warn('.env file not found in current or parent directory');
}



const secretKey = process.env.SECRET_KEY

class VirtualUser {
Expand Down

0 comments on commit 4f458fc

Please sign in to comment.