'typescript code to write the generate content into a new created file

Right now I am developing a VS Code extension, I want to store the generate HTML code into a system auto-created HTML file, but I dont know how to do this in typescript, please help, thanks a lot



Solution 1:[1]

This is not directly related to Typescript, but to node-js itself.

You could utilize fs module from node ( either use writeFile or writeFileSync), like this -

import { writeFile } from "fs";

const saveToFile = async (filePath: string) => Promise<void> {
  await writeFile(filePath, dataToWrite, err => console.log(err));
}

Could use following references - Writing files with NodeJs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ariyanas