Can't find json file in correct path.

I'm trying to get values from 2 separate json files but cannot find the files.
async function processMembers(members) {
let unityJSON;
let commerceJSON;

// Constructing absolute paths
const unityFilePath = path.resolve(__dirname, "res", "json", "unity_credits.json");
const commerceFilePath = path.resolve(__dirname, "res", "json", "commerce_credits.json");

console.log(`Attempting to read Unity credits JSON from: ${unityFilePath}`);
try {
const unityData = await fs.readFile(unityFilePath, "utf8");
unityJSON = JSON.parse(unityData);
} catch {
console.warn('Unity credits JSON not found!');
}

console.log(`Attempting to read Commerce credits JSON from: ${commerceFilePath}`);
try {
const commerceData = await fs.readFile(commerceFilePath, "utf8");
commerceJSON = JSON.parse(commerceData);
} catch {
console.warn('Commerce credits JSON not found!');
}
async function processMembers(members) {
let unityJSON;
let commerceJSON;

// Constructing absolute paths
const unityFilePath = path.resolve(__dirname, "res", "json", "unity_credits.json");
const commerceFilePath = path.resolve(__dirname, "res", "json", "commerce_credits.json");

console.log(`Attempting to read Unity credits JSON from: ${unityFilePath}`);
try {
const unityData = await fs.readFile(unityFilePath, "utf8");
unityJSON = JSON.parse(unityData);
} catch {
console.warn('Unity credits JSON not found!');
}

console.log(`Attempting to read Commerce credits JSON from: ${commerceFilePath}`);
try {
const commerceData = await fs.readFile(commerceFilePath, "utf8");
commerceJSON = JSON.parse(commerceData);
} catch {
console.warn('Commerce credits JSON not found!');
}
Attempting to read Unity credits JSON from: [path of __dirname]\res\json\unity_credits.json
Unity credits JSON not found!
Attempting to read Commerce credits JSON from: [path of __dirname]\res\json\commerce_credits.json
Commerce credits JSON not found!
Attempting to read Unity credits JSON from: [path of __dirname]\res\json\unity_credits.json
Unity credits JSON not found!
Attempting to read Commerce credits JSON from: [path of __dirname]\res\json\commerce_credits.json
Commerce credits JSON not found!
2 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Evena
EvenaOP2mo ago
Ah yeah that's my bad, thank you, didn't think about it since the overall project is

Did you find this page helpful?