DEV Community 👩‍💻👨‍💻


Posted on

Asynchronous CRUD Operations in Node js

What is Asynchronous ?

Asynchrony, in programming world, refers to the occurrence of events independent of the main program flow and ways to deal with this kind of events.

Image description


The term "CRUD" refers to the four operations that are thought to be required to develop a data storing application: create, read, update, and delete. It originates from the area of computer programming. Any data storage device, such as a solid-state drive or a hard disc, that keeps power after the device is turned off is referred to as persistent storage. In contrast, volatile memory, which includes random access memory and internal caching, stores information that will be lost when a device loses power.

Image description

1 Create a file and data into it

const fs = require ("fs");

fs.writeFile("Newfile.txt","sample data" ,(err) =>{

Enter fullscreen mode Exit fullscreen mode

2 To append changes

fs.appendFiles("Newfile.txt","sample data changed" ,(err) =>{

Enter fullscreen mode Exit fullscreen mode

3 To read file

fs.readFile("Newfile.txt",'utf-8',(err,data) =>{

Enter fullscreen mode Exit fullscreen mode

4 To delete a file

fs.unlink("Newfile.txt",(err) =>{

Enter fullscreen mode Exit fullscreen mode

Check out my Github for source code :-

Top comments (0)

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.