How to read 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

Read a text file

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

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

const text = Deno.readTextFile("./data.json");
text.then((response) => console.log(response));

Here the text constant will return the resulted content in this operation.

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

deno run --allow-read maint.ts

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

Published by


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: Logo

You are commenting using your 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.