Next.js Discord

Discord Forum

Access Local Files in Server Action

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I'm trying to setup a local SQLite database using libSQL and Drizzle.
I have my database client that I export and access from within the server action, but the paths seem wacky in server actions.

import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema';
import path from 'path';

const db_path = path.resolve(__dirname, 'myDB.db');

console.log({ db_path });

const client = createClient({ url: db_path });
export const db = drizzle(client, { schema });


{
  db_path: '/Users/skollie/RSC/[project]/database/db.ts [app-rsc] (ecmascript)/myDB.db'
}

I have no idea what the [project] directory is or the [app-rsc] (ecmascript)

8 Replies

Asian black bearOP
You can replicate it by trying to access a file in your codebase using fs from a server action
@Masai Lion But do you really need an absolute path?
Asian black bearOP
Only tried the absolute path because just doing "file:./myDB.db" didn't work. Trust me that was the first thing I tried.
If not an absolute path, how would you access a local file in your codebase within a server action?