簡體   English   中英

Node.js writeFileSync 未正確寫入文件

[英]Node.js writeFileSync not writing to files properly

我們在 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)
    const $ = cheerio.load(cssData + videoHtml + pageData.content); 
 fs.writeFileSync(file, $.html(), { encoding: 'utf8' , mode : 0755})
 fs.closeSync(indexFile)

嘗試在選項中添加模式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM