Skip to content

Instantly share code, notes, and snippets.

@chadbr
chadbr / writeJSON.ts
Last active May 1, 2019 01:51
Write a file with Typescript 3.x and node 10.x fs/promises
import { promises as fs } from 'fs';
import { EOL } from 'os';
export class SomeClass {
async asyncFileWriteJSON<T>(listOfObjects: Array<T>, filename: string): Promise<void> {
try {
if (listOfObjects && listOfObjects.length > 0) {
const file = filename;
let fd = await fs.open(file, 'w');