How do I find the project directory?

This feels like a stupid question but I cant figure it out. I'm trying to append records to a CSV when the user does certain actions. I have the folder made called "data". Using the code below, in test on my local machine, the files are written successfully. And the path in the logs makes sense. But in production, I get an error saying the path doesnt exist. My root folder is "gogh-shopping". But the path where it tries to find the "data" folder is starting with "app". Is that expected? How do I point to the correct directory in prod? Here is my code:
const DATA_DIR = path.join(__dirname, 'data');

const appendToCSV = async (filename, data) => {
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {...
const DATA_DIR = path.join(__dirname, 'data');

const appendToCSV = async (filename, data) => {
const csvPath = path.join(DATA_DIR, `${filename}.csv`);

try {...
4 Replies
Percy
Percy9mo ago
Project ID: b624c17e-a6de-4867-bbb0-89bdb4c2eb04
ManuelMaccou | Mosaic
b624c17e-a6de-4867-bbb0-89bdb4c2eb04
maddsua
maddsua9mo ago
If you want to store data persistently between deploys Railway Volumaes is what you wanna use instead of saving to the project directory. https://docs.railway.app/reference/volumes The "path does not exist" error is likely to be caused by the directory not actually being present in a container, as empty directories don't get uploaded via cli or github integration. What you wanna do here is to check if a directory exists and if it doesn't, create one using fs.mkdirSync with recursive option set to true just to avoid any further issues Also, your app is placed to the app directory by default, that's expected behavior
ManuelMaccou | Mosaic
Thatnks for such a thorough response! I'll check out volumes
Want results from more Discord servers?
Add your server