M
MastraAI7d ago
Flix

Dealing with file path to load csv file

Hi guys, i need help for a simple question I have a tree project like this:
.
├── package.json
├── product-embeddings.json
├── src
│ └── mastra
│ ├── agents
│ ├── api
│ ├── data.csv
│ ├── index.ts
│ ├── scripts
│ ├── tools
│ └── workflows
├── tsconfig.json
└── yarn.lock
.
├── package.json
├── product-embeddings.json
├── src
│ └── mastra
│ ├── agents
│ ├── api
│ ├── data.csv
│ ├── index.ts
│ ├── scripts
│ ├── tools
│ └── workflows
├── tsconfig.json
└── yarn.lock
how do i reference the product-embeddings.json using path? I've tried using this
const projectRoot = process.cwd();
const embeddingsData = JSON.parse(fs.readFileSync(path.join(projectRoot, 'product-embeddings.json'), 'utf-8'));
const projectRoot = process.cwd();
const embeddingsData = JSON.parse(fs.readFileSync(path.join(projectRoot, 'product-embeddings.json'), 'utf-8'));
but it reference the path on MyMastraProject/.mastra/output/product-embeddings.json instead of MyMastraProject/product-embeddings.json
4 Replies
Mastra Triager
GitHub
[DISCORD:1427875437492568115] Dealing with file path to load csv fi...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1427875437492568115 Hi guys, i need help for a simple question I have a tree project like this: ├── packag...
LekoArts
LekoArts7d ago
Hi! You can use the public folder: https://mastra.ai/en/docs/deployment/server-deployment#public-folder Place the csv there and then reference your file with a relative path
Deploy a Mastra Server
Learn how to deploy a Mastra server with build settings and deployment options.
Flix
FlixOP6d ago
is there any official way to access the file? i got this error intermittently
file:///data/project/.mastra/output/mastra.mjs:71780
const projectRoot = path.resolve(__dirname);
^

ReferenceError: Cannot determine intended module format because both require() and top-level await are present. If the code is intended to be CommonJS, wrap await in an async function. If the code is intended to be an ES module, replace require() with import.
at file:///data/project/.mastra/output/mastra.mjs:71780:34
at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
code: 'ERR_AMBIGUOUS_MODULE_SYNTAX'
}
file:///data/project/.mastra/output/mastra.mjs:71780
const projectRoot = path.resolve(__dirname);
^

ReferenceError: Cannot determine intended module format because both require() and top-level await are present. If the code is intended to be CommonJS, wrap await in an async function. If the code is intended to be an ES module, replace require() with import.
at file:///data/project/.mastra/output/mastra.mjs:71780:34
at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
code: 'ERR_AMBIGUOUS_MODULE_SYNTAX'
}
here's the code I used:
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const projectRoot = path.resolve(__dirname);
const CSV_FILE_PATH = process.env.CSV_FILE_PATH || path.join(projectRoot, 'data.csv');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const projectRoot = path.resolve(__dirname);
const CSV_FILE_PATH = process.env.CSV_FILE_PATH || path.join(projectRoot, 'data.csv');
LekoArts
LekoArts6d ago
It should just be CSV_FILE_PATH = './data.csv', no need for dirname

Did you find this page helpful?