Skip to content

process.cwd() Different paths in development and production environment #11197

Answered by SabrioBiblio
SabrioBiblio asked this question in Help
Discussion options

You must be logged in to vote

I solved this issue.
Everything is quite logical.
However, I don’t quite remember the decision, since I haven’t touched the project for more than two months.
But here is an example with posts that I implemented

/*The posts folder is in the root of the project*/
const pathToPosts = process.env.NODE_ENV === "development" ? "/posts" : "posts";
const postsDirectoryPath = process.cwd();
    const files = await fs.readdir(path.join(postsDirectoryPath, pathToPosts), {
      withFileTypes: true,
    });

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by SabrioBiblio
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
7 participants