diff --git a/server_test/virtual-user-ws.js b/server_test/virtual-user-ws.js index 2ad7d28..5345a79 100644 --- a/server_test/virtual-user-ws.js +++ b/server_test/virtual-user-ws.js @@ -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 {