Posts

Showing posts from April, 2021

Path module in node js

Today we will explore path module in node js. As the name suggests this module gives you the path. We started with fs module , then we went to os module & now moving towards path module. Using path module we can find directory name , filename on which we are working etc. I will cover the important part , for the detail information I will provide the documentation link. One thing, we need to always remember that, whenever we are using node modules we need to require it first . We saw fs & os modules as well, in that also we required the module first & then started playing around with it. To require path module const path = require( 'path' ); So we have required our module, let's play with it now. To get directory name path.dirname(path of file); A typeError is thrown if path of file is not string. To get extension of file path.extname(path of file); To get directory name, root,filename,basename & extension

OS module in node js

Os module in nodejs What is os module in node js? What is it's use? OS stands for Operating system. This module provides information on your operating system.Everybody must be knowing what are operating systems. An operating system (os) is a system software that manages computer hardware ,software etc. Examples of operating system are widows , mac etc. So, basically this module gives details about your operating system like architecture, hostname etc. Imagine you don't know the architecture of your os. In order to find it we need to go to device manager & bla bla bla(I actually don't know). This process is too long like I have used this process(Googled it actually)several times but still don't know it. But writing only line of code in node js you can know what is the architecture of your os . As we know, before using any module in node js we need to require it. const os = require ( "os" ); To get cpu architecture os.arch

Fs module in node js (Asynchronous)

Fs module in nodejs (A synchronous version) I would like to take you through the basics to understand asynchronous version of fs module. Let's see what are parameters & arguments. Eg : function add (a,b){ return a + b; } Here, a & b are called parameters. Eg : add ( 5 , 6 ) ; //calling a function Here 5 & 6 are arguments. So, in short parameters are given while defining the function & arguments are given while calling the function. So we have understood parameter & arguments. Next, we will see what are higher order functions & callbacks. When we pass a function as parameter to another function, the second function is called as a higher order function. The function passed as a parameter is called callback function. Now let's see how to use fs module in asynchronous version. In order to use modules in nodejs, we need to require it first. const fs = require ( "fs" );

Fs module in node js!!!

Fs module in node js What is fs module? fs stands for file system. What is the use of this module?why is it so important? My journey when I started with nodejs, this was first step. So, let's answer the question what is the use of this module? This module as name suggests allows us to work with files. Using this module, we can 1. Create files 2. Read files 3 Append text in file. 4. Delete files We can perform these operations in two versions 1. Synchronous 2 Asynchronous Let's understand Synchronous & Asynchronous. Now, let's take an example in a hotel, the waiter takes order of first customer & then gives it to the cook & after the order is served for the customer 1 ,the waiter moves to next customer. This is called Synchronous. The second operation will be performed only after the first operation is performed successfully. You must have guessed what is asynchronous version. Consider our hotel example, the waiter