Node JS readFileSync严格模式下不允许八进制转义序列

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Node JS readFileSync严格模式下不允许八进制转义序列相关的知识,希望对你有一定的参考价值。

我想在节点js中读取一个文本文件

这是我的代码:

const fs = require('fs');
const contents = fs.readFileSync('1.txt', 'utf8');
console.log(contents);

但我得到了这个错误:

(node:5168) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Octal escape sequences are not allowed in strict mode.
(node:5168) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

此时,我该如何阅读文本文件?

答案

该程序运行良好问题出在我写得不好的文件的名称

以上是关于Node JS readFileSync严格模式下不允许八进制转义序列的主要内容,如果未能解决你的问题,请参考以下文章

前端笔试题目记录

JS严格模式

this指向 - Node环境

严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数

JS严格模式

js备战春招の四の严格模式