Read and write a text file in typescript

前端 未结 4 2119
暖寄归人
暖寄归人 2020-12-10 00:39

How should I read and write a text file from typescript in node.js? I am not sure would read/write a file be sandboxed in node.js, if not, i believe there should be a way i

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 00:56

    import { readFileSync } from 'fs';
    
    const file = readFileSync('./filename.txt', 'utf-8');
    

    This worked for me. You may need to wrap the second command in any function or you may need to declare inside a class without keyword const.

提交回复
热议问题