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

问题描述 投票:0回答:1

我想在节点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 utf-8 fs
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.