Author -  Sai gowtham

How to write files in Deno

In this tutorial, we are going to learn about writing data to files with deno using fs module.

Deno has a standard fs module, that contains different types of methods to manipulate the file system.

Using the writeFileStr() method

The writeFileStr() method asynchronously writes data to the file in deno.

Data will be in string format.

Example:

app.js
import { writeFileStr } from "https://deno.land/std/fs/mod.ts";

const writeName = await writeFileStr("./names.txt", "Gowtham");

The first argument in the writeFileStr() method is the path of the file you need to write, the second argument is the data you need to add to that file.

To run it, we need to give write permissions of names.txt file to deno by using --allow-read flag.

deno run --unstable  --allow-write=./names.txt  app.js

If the names.txt file doesn’t exist in your file system, the writeFileStr() method will create one.

Note: All the methods inside a file system module are currently unstable, so that we have used the --unstable flag to enable it during runtime.

Similarly, we can use the writeFileStrSync() method to write the file synchronously.

app.js
import { writeFileStrSync } from "https://deno.land/std/fs/mod.ts";

const writeName = await writeFileStrSync("./names.txt", "Gowtham");

Note: Both methods replace the entire contents of the file with the data you passed in the second argument.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY