Video instructions and help with filling out and completing Are Form 2220 Filers

Instructions and Help about Are Form 2220 Filers

Hello guys welcome to the next video on node.js to troll for beginners and in this video I'm going to show you how we can use filesystem module in node.js which is a built-in module now node implements file i/o using simple wrapper around the standard POSIX functions and this is done using node file system module or simply FS module in no js' now let's see first of all how we can add FS module so just write var FS is equal to require and then you just add FS ok and this is how you can add FS module now this FS module you can use for various input/output functions related to file system in this video particularly we are going to real see how we can use this FS module to read and write to a file synchronously and asynchronously right so first of all we will use this file to read from a file synchronously but for that we need a file txt file which we can read so I'm going to create a text file for example I will name it as test dot txt and in this text file I'm going to write some things and let's you know copy and paste this line ok so this is what we want to read from our file system object which we have you know created using this file system module so for reading this file synchronously what we can do is we can just use file and first of all we need to assign this output which we read so we can just write to our and then we can just say red string is equal to FS dot read file sync ok so just write read file sync and this method will allow us to read our files synchronously okay and then give the name of your file and because this file is in the same folder you just need to give the name of the file not the part because it's in the same folder so just write test dot txt and the second argument which we want to pass here will be the encoding type so just write for example utf-8 and now let's try to print whatever we have you know read from the file to the console so just write console dot log and we will just print this string here what ever we have read so it should be red string and then we are going to run it so open your terminal and just run it using node app dot J's and you can see our file is red so our file content let's see what was the file content and what the terminal is showing right so same content as the file so this file system module enables us to read the file synchronously and if you want to write this file to another file or write the content of the file which you have read to another file new file for example what we can do so we can just write FS dot right file sync so just write right file sink and then just pass this result to the argument okay so right right file sink can be used to write to the file synchronously right and this file right file method takes two arguments the first will be the name of your file so let's create the name for example test to dot txt and the second argument is the content itself right and let's run our code and let's see what happens this time so just see here what happens here whenever we will run this code and you can see this text too is created when we run the code and the content of text too is same as test1 dot txt or test dot txt right so in this way you can use this to read and write to the file synchronously now FS mode you'll also have the async method and this will allow us to read or write to a file asynchronously right so this for this we just need to use the method called file name without sync so by default if you know about node.js node.js is a asynchronous you know program so whenever you write the program it runs asynchronously and what I mean by asynchronous is I'm going to show you in just a second so just write this once again we want to read the content of test a txt file and just call a method read file and the first argument will be the same and the second argument we want to pass here is the callback method well let's say we can do it in the last argument also right so just write function and then just say error as a force argument and data as the second argument okay and then give a curly bracket here and press ENTER and in here for example if there is some problem in reading we want to return error so just call this argument first argument which we have passed in the callback function which is this one and then we can console era right so just write return console dot error and then pass this error here as an argument okay otherwise if there is no error in reading we can just console.log the content so instead of console.log outside the you know read file method we can just you know call it inside or call back okay something like this and this argument which it takes now is data because data will contain your content of your file which you have read okay for now let's remove this line of code and in here we will just call console.log and let's say we just want to print the pile is red for example okay and let's run the code once again and let's see what happens so what I'm going to