我应该如何在 node.js 中从 typescript 读取和写入文本文件? 我不确定是否会在 node.js 中对文件进行沙盒读取/写入,如果没有,我相信应该有一种访问文件系统的方法。
最佳答案
believe there should be a way in accessing file system.
使用 npm i @types/node
包含 node.d.ts
。然后新建一个tsconfig.json
文件(npx tsc --init
),创建一个.ts
文件如下:
import * as fs from 'fs';
fs.readFileSync('foo.txt','utf8');
您也可以在 fs
中使用其他功能:https://nodejs.org/api/fs.html
更多
关于node.js - 在 typescript 中读取和写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33643107/