N
Nuxt6mo ago
bqst

Server API & CSV issue

Hey everyone, I’m having an issue with exposing a CSV file through a server API endpoint. Here’s what I’m working with: • CSV Location: data/products.csv • API Endpoint: server/api/v1/products.get.ts I’m using papaparse for parsing the CSV as follows:
const filePath = path.resolve('data/products.csv');
const fileContent = fs.readFileSync(filePath, 'utf8');
const products = Papa.parse(fileContent, { header: true }).data;
...
const filePath = path.resolve('data/products.csv');
const fileContent = fs.readFileSync(filePath, 'utf8');
const products = Papa.parse(fileContent, { header: true }).data;
...
This setup works perfectly on my local machine. However, when I deploy it to Vercel, I get the following error:
ENOENT: no such file or directory, open '/var/task/data/products.csv'
ENOENT: no such file or directory, open '/var/task/data/products.csv'
Any ideas on what might be causing this? I think I might have misconfigured something in the deployment settings. Thanks in advance for any help!
1 Reply
bqst
bqstOP6mo ago
Fixed. Found infos on Vercel: https://vercel.com/guides/how-can-i-use-files-in-serverless-functions#using-nuxt I used :
const assets = useStorage('assets:server')
const productsCsv = await assets.getItem('products.csv')
const products = Papa.parse(productsCsv, { header: true }).data
...
const assets = useStorage('assets:server')
const productsCsv = await assets.getItem('products.csv')
const products = Papa.parse(productsCsv, { header: true }).data
...
How to read files in Vercel Functions
Learn how to import, read, and store files inside Vercel Functions.
Want results from more Discord servers?
Add your server