问题
I have the following code
fs.createWriteStream( fileName, {
flags : 'a',
encoding : 'utf8',
mode : 0644
});
I get a lint error
Octal literals are not allowed in strict mode.
What is the correct way to do this code so I won't get a lint error?
回答1:
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?
回答2:
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
回答3:
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
回答4:
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"
});
来源:https://stackoverflow.com/questions/23609042/how-to-avoid-octal-literals-are-not-allowed-in-strict-mode-with-createwritestr