Issue with accessing filepath outside
/backend
folder
technoph1le
FREEOP

8 months ago

Hi, everyone!

I have this following folder structure for my project:

/backend
  -> scripts
    -> snippetParser.ts
/frontend
/snippets

Inside the snippetParser.ts file, there's a following code:

import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const snippetPath = join(__dirname, "../../snippets");

Basically, when running the code locally, it accesses the snippets perfectly fine, however, after publishing to Railway to run the script on production, it throws an error "No such file or directory".

I'm kinda stuck here. Would love to hear if anyone has a good solution for it.

4 Replies

technoph1le
FREEOP

8 months ago

ed2db2f4-ee72-4fae-bc0d-a999038e6593


uxuz
MODERATOR

8 months ago

Hey, how did you deploy your monorepo? By the looks of it, you are deploying a shared monorepo, here is the documentation regarding it: https://docs.railway.com/guides/monorepo#deploying-a-shared-monorepo.


technoph1le
FREEOP

8 months ago

it's a monorepo. Thanks


swiftdev12
HOBBY

8 months ago

@technoph1le,

import { join } from "path";
import { readdirSync, readFileSync } from "fs";


const snippetPath = join(process.cwd(), "snippets");

console.log("[DEBUG] process.cwd():", process.cwd());
console.log("[DEBUG] snippetPath:", snippetPath);

Maybe try this oen


Loading...