How to get root directory path in NextJs 13?
Answered
Cinnamon posted this in #help-forum
CinnamonOP
I need a way to get the root directory path of the application, as I have a folder named "upload" and I want to write files there. But I do not know how to get the root directory path of my application.
I tried
A suggestion was to add a global variable in index.js, but there is no such file in NextJs.
I tried
process.cwd() but someone said that is not reliable.A suggestion was to add a global variable in index.js, but there is no such file in NextJs.
Answered by fuma
Why?
If your Next.js app is hosted in a serverless environment (like Vercel), these files might not be persistent.
process.cwd is reliable, but you're not supposed to write files. If your Next.js app is hosted in a serverless environment (like Vercel), these files might not be persistent.
7 Replies
Why?
If your Next.js app is hosted in a serverless environment (like Vercel), these files might not be persistent.
process.cwd is reliable, but you're not supposed to write files. If your Next.js app is hosted in a serverless environment (like Vercel), these files might not be persistent.
Answer
global variable? Impossible, the path is no longer the same after deploying it
Our app allows for file uploads of documents and we want to save those documents internally and save their path in database
process.cwd is reliable, don't worrysince you have a private server, why not let's go wild
CinnamonOP
Okay, thank you!