小编Flo*_*n T的帖子

使用 firebase 函数读取文件

我有一个 Firebase 函数,想要读取一个存储在子文件夹中的 html 文件。

\n
\xe2\x94\x80\xe2\x94\x80 functions\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n    |   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.ts // Here is the function\n    |   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 html\n    |   |   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 template.html // the file I want to read\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试通过读取文件, const html = fs.readFileSync('./html/template.html');但它总是告诉我

\n
\n

错误:ENOENT:没有这样的文件或目录,打开 './html/template.html'\nat Object.openSync

\n
\n

我解决了 stackoverflow 上与这个主题相关的几乎所有问题,但没有任何效果对我有用。我还尝试将文件放在与函数相同的文件夹中,但它总是给我错误。

\n

我是否需要安装某些软件包或以某种方式导入文件才能访问它?

\n

file firebase typescript google-cloud-platform google-cloud-functions

5
推荐指数
2
解决办法
3388
查看次数