File path in NextJS api route not resolving

I'm trying to resolve a file path in NextJS.

I understand that API routes are working a little bit differently when deployed to Vercel. In order to create a correct path to the file I assumed I had to do this:

const svg = fs.readFileSync(
  path.join(process.cwd(), "img", "file.svg"),
  "utf-8",
);

// ENOENT: no such file or directory

But I cannot make it work. The file cannot be found under that path.

How can I find the correct path for a file in NextJS api routes?

I've followed the documentation of this.

  • Next version is: 11.1.3
  • When logging the path, it is giving /var/task/data/project-root/img/file.svg


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation