【问题标题】:Node.js writeFileSync not writing to files properlyNode.js writeFileSync 未正确写入文件
【发布时间】:2020-01-29 09:38:45
【问题描述】:

我们在 Web 应用程序中使用 Node.js 编写文件时遇到问题。 Node.js 是使用 IISNode 安装的。

在我们的开发服务器上一切正常,但相同的代码在我们的生产服务器(Windows 7、IIS7、Windows Server 2008 R2 Standard、Service pack 1)上出现问题。 基本上,在单击按钮时,节点会创建多个 HTML 文件,并将内容写入其中。问题是内容没有写入所有创建的文件。所有文件都已创建,但有些文件留空,没有内容。

以下是用于创建和写入文件的代码摘录:

const $ = cheerio.load(cssData + videoHtml + pageData.content);
let indexFile = fs.openSync(file, 'w+')
fs.writeFileSync(indexFile, $.html(), { encoding: 'utf8' })
fs.closeSync(indexFile)

【问题讨论】:

    标签: javascript node.js iis-7 windows-server-2008-r2


    【解决方案1】:
        const $ = cheerio.load(cssData + videoHtml + pageData.content); 
     fs.writeFileSync(file, $.html(), { encoding: 'utf8' , mode : 0755})
     fs.closeSync(indexFile)
    

    尝试在选项中添加模式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多