prompt: Give me an asynchronous NodeJS function in TypeScript that uses the fs/promises module, already imported as fsp, to create a file at a given path with given data and create its whole directory structure if any of it doesn't exist.
chosen.role: system
chosen.content: A chat.
chosen.role: user
chosen.content: Give me an asynchronous NodeJS function in TypeScript that uses the fs/promises module, already imported as fsp, to create a file at a given path with given data and create its whole directory structure if any of it doesn't exist.
chosen.role: assistant
chosen.content: Here's an asynchronous Node function in Typescript that will create a file and its directory structure at a given path.
  
  async function createFile(fileName: string, data: string) {
      await fsp.mkdir(dirname(fileName), {
          recursive: true
      });
      await fsp.writeFile(fileName, data);
  }
rejected.role: system
rejected.content: A chat.
rejected.role: user
rejected.content: Give me an asynchronous NodeJS function in TypeScript that uses the fs/promises module, already imported as fsp, to create a file at a given path with given data and create its whole directory structure if any of it doesn't exist.
rejected.role: assistant