how to avoid “Octal literals are not allowed in strict mode” with createWriteStream

北战南征 提交于 2019-12-02 20:04:57

I don't have a node installation at hand, but looking at sources it seems that they allow strings as well:

  mode     : '0644'

Does it work?

You can write them like this :

 mode     : parseInt('0644',8)

In node and in modern browsers (see compatibility), you can use octal literals:

 mode     : 0o644

I came through this problem while using it in a scape squence:

console.log('\033c'); // Clear screen

All i had to do was convert it to Hex

console.log('\x1Bc'); // Clear screen

You can avoid this problem by using mode into string type.

1st Method

 let mode = "0766";
 fs.createWriteStream( fileName, {
        flags    : 'a',
        encoding : 'utf8',
        mode     : mode
    });

or

2nd Method

 fs.createWriteStream( fileName, {
        flags    : 'a',
        encoding : 'utf8',
        mode     : "0766"
    });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!