How to create a text file in Deno


Deno is asynchronous JavaScript/TypeScript runtime. If you are not sure how and what’s of Deno, here is the links

Create a textfile

Deno API allows developers to write files using writeTextFile() which return a promise. A promise is similar to future in flutter, the result of the job will come in future.

You know that Deno is async by default, in the async world program continue working without interrupting other jobs.

const write = Deno.writeTextFile("./hello.txt", "Hello World!");
write.then(() => console.log("File written to ./hello.txt"));

Here the write constant will return result / only if the operation is succeeded.

To run this script yo may allow deno to use –allow-write permission.

deno run --allow-write maint.ts

All of my Deno projects will be published on my GitHub Repo, so keep watching.

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.