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

时间:2018-03-05 09:47:44

标签: node.js utf-8 fs

我想在节点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.

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

1 个答案:

答案 0 :(得分:0)

该计划运作良好 问题在于我写得不好的文件的名称