

{"id":103553,"date":"2021-12-01T09:00:47","date_gmt":"2021-12-01T03:30:47","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=103553"},"modified":"2021-12-01T12:26:07","modified_gmt":"2021-12-01T06:56:07","slug":"nodejs-file-system","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/","title":{"rendered":"NodeJS File System"},"content":{"rendered":"<p>Nodejs has a builtin module for the file system. We will be using this to perform various operations on files like creating, updating, renaming, deleting etc. So let&#8217;s start!!!<\/p>\n<h3>Nodejs Create File:<\/h3>\n<p>It has mainly 3 methods as below:<\/p>\n<h4>1. Append file<\/h4>\n<p>The fs.appendFile() method\u2019s second argument takes the text that we want to append, and then it appends at the end of the file if the given file does not exist then the file will be created.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.appendfile(filename,text,callback)<\/p>\n<p><strong>Code for appending text in a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs=require(\u2018fs\u2019)\r\nfs.appendFile('DataFlairDemo.txt', 'welcome to DataFlair', function (err) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-append-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103981\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-append-file.webp\" alt=\"nodejs fs append file\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-append-file.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-append-file-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>2. Open file<\/h4>\n<p>The fs.open() method\u2019s second argument is &#8220;w&#8221; for &#8220;writing&#8221;, which indicates that the file is opened for writing and if it does not exist then an empty file is created.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.open(path, flags[, mode], callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>flags \u2212 it indicates how the file is to be opened.<\/li>\n<li>mode \u2212 sets the mode of the file.<\/li>\n<li>callback \u2212 it is the callback function, takes arguments (err, fd).<\/li>\n<li>path \u2212 path of the file.<\/li>\n<\/ul>\n<p><strong>Code for opening a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs=require(\u2018fs\u2019)\r\nfs.open('DataFlairDemo.txt', 'w', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-openfile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103982\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-openfile.webp\" alt=\"nodejs fs openfile\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-openfile.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-openfile-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>You can see that a file has been added.<\/p>\n<h4>3. WriteFile:<\/h4>\n<p>The fs.writeFile() method\u2019s second argument takes the text that we want to write, and then it overrides the content available in the file if the given file does not exist then the file will be created.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.writeFile(filename, data[, options], callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>flags \u2212 it indicates how the file is to be opened.<\/li>\n<li>path \u2212 path of the file.<\/li>\n<li>data \u2212 String that has to be written into the file.<\/li>\n<li>options \u2212 The third parameter is an object which will hold encoding, mode and flag.<\/li>\n<\/ul>\n<p><strong>Code for writing in a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require('fs');\r\nfs.writeFile('DataFlairDemo.txt', 'Learn Node.js from DataFlair', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103983\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile.webp\" alt=\"nodejs fs writefile\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>Nodejs Update File:<\/h3>\n<p>It has mainly 2 methods:<\/p>\n<h4>1. fs.appendFile()<\/h4>\n<p>The fs.appendFile() method\u2019s second argument takes the text that we want to append, and then it appends at the end of the file, if the given file does not exist then the file will be created.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.appendfile(filename,text,callback)<\/p>\n<p><strong>Code for fs.appendFile()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs=require(\u2018fs\u2019)\r\nfs.appendFile('DataFlairDemo.txt', 'welcome to DataFlair', function (err) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-update-file-by-append-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103984\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-update-file-by-append-file.webp\" alt=\"nodejs update file by append file\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-update-file-by-append-file.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-update-file-by-append-file-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>2. fs.writeFile():<\/h4>\n<p>The fs.writeFile() method\u2019s second argument takes the text that we want to write, and then it overrides the content available in the file if the given file does not exist then the file will be created.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.writeFile(filename, data[, options], callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>flags \u2212 it indicates how the file is to be opened.<\/li>\n<li>path \u2212 path of the file<\/li>\n<li>data \u2212 String that has to be written into the file.<br \/>\noptions \u2212 The third parameter is an object which will hold encoding, mode and flag<\/li>\n<\/ul>\n<p><strong>Code for writing in a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require('fs');\r\nfs.writeFile('DataFlairDemo.txt', 'Learn Node.js from DataFlair', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103985\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile-1.webp\" alt=\"nodejs fs writefile\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile-1.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-writefile-1-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>3. Read File:<\/h4>\n<p>It is used to read files present in your system.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.read(fd, buffer, offset, length, position, callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>fd \u2212 it is a file descriptor returned by fs.open().<\/li>\n<li>buffer \u2212 buffer for writing the data.<\/li>\n<li>offset \u2212 buffer to start writing from.<\/li>\n<li>length \u2212 specifies the number of bytes to read.<\/li>\n<li>position \u2212 specifies where to begin reading from in the file.<\/li>\n<li>callback \u2212 it is the callback function, takes arguments (err, fd)<\/li>\n<\/ul>\n<p><strong>Code for reading a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require('fs');\r\nfs.readFile('DataFlairDemo.txt', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Saved!<\/div>\n<h4>4. Delete File:<\/h4>\n<p>In order to delete a file we will use fs.unlink()method of the file system.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.unlink(path, callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>callback \u2212 it is the callback function, takes arguments (err, fd).<\/li>\n<li>path \u2212 path of the file<\/li>\n<\/ul>\n<p><strong>Code for deleting a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require('fs');\r\nfs.unlink('DataFlairDemo.txt', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p>You can see that the file is no longer visible.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-delete.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-103986\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-delete.webp\" alt=\"nodejs fs delete\" width=\"1366\" height=\"723\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-delete.webp 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-fs-delete-768x406.webp 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>5. Rename File:<\/h4>\n<p>If we want to rename a file we will use the fs.rename() method of the file system module.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p>fs.rename(name,newName)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<ul>\n<li>Name &#8211; current file name<\/li>\n<li>newName &#8211; new file name<\/li>\n<\/ul>\n<p><strong>Code for renaming a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require('fs');\r\nfs.rename('DataFlair1.txt', 'DataFlair2.txt', function (err, file) {\r\nif (err) throw err;\r\nconsole.log('Saved!');\r\n});<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Saved!<\/div>\n<h4>6. Close a file:<\/h4>\n<p>In order to close a file which was opened we will use the fs.close method of the file system module.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.close(fd, callback)<\/p>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li>fd \u2212 file descriptor returned by fs.open() method.<\/li>\n<li>callback \u2212 arguments other than a possible exception are provided to this callback.<\/li>\n<\/ul>\n<p><strong>Code of closing a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require(\"fs\");\r\nvar buf =Buffer.alloc(1024);\r\n\r\nconsole.log(\"opening file\");\r\nfs.open('input.txt', 'r+', function (err, fd) {\r\nif (err) {\r\nreturn console.error(err);\r\n}\r\nconsole.log(\"opened successfully!\");\r\nconsole.log(\"reading the file\");\r\n\r\nfs.read(fd, buf, 0, buf.length, 0, function (err, bytes) {\r\nif (err) {\r\nconsole.log(err);\r\n}\r\n\r\nif (bytes &gt; 0) {\r\nconsole.log(buf.slice(0, bytes).toString());\r\n}\r\n\r\nfs.close(fd, function (err) {\r\nif (err) {\r\nconsole.log(err);\r\n}\r\nconsole.log(\"closed successfully.\");\r\n});\r\n});\r\n});<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">opening file<br \/>\nopened successfully!<br \/>\nreading the file<br \/>\nWelcome to DataFlair<br \/>\nclosed successfully.<\/div>\n<h4>7. Truncate file:<\/h4>\n<p>Many files contain very long text, in order to see a small portion of that file we will use the truncate method of the file system module.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p>fs.ftruncate(fd, len, callback)<\/p>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li>fd \u2212 file descriptor returned by fs.open().<\/li>\n<li>len \u2212 length of the file after which the file will be truncated.<\/li>\n<li>callback \u2212 arguments other than a possible exception are provided to this callback.<\/li>\n<\/ul>\n<p><strong>Code for truncating a file:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var fs = require(\"fs\");\r\nvar buf = Buffer.alloc(1024);\r\n\r\nconsole.log(\"opening file\");\r\nfs.open('input.txt', 'r+', function (err, fd) {\r\nif (err) {\r\nreturn console.error(err);\r\n}\r\nconsole.log(\"opened successfully!\");\r\nconsole.log(\"truncating the file after 10 bytes\");\r\n\r\nfs.ftruncate(fd, 10, function (err) {\r\nif (err) {\r\nconsole.log(err);\r\n}\r\nconsole.log(\"truncated successfully.\");\r\nconsole.log(\"reading the same file\");\r\n\r\nfs.read(fd, buf, 0, buf.length, 0, function (err, bytes) {\r\nif (err) {\r\nconsole.log(err);\r\n}\r\n\r\nif (bytes &gt; 0) {\r\nconsole.log(buf.slice(0, bytes).toString());\r\n}\r\n\r\nfs.close(fd, function (err) {\r\nif (err) {\r\nconsole.log(err);\r\n}\r\nconsole.log(\"closed successfully.\");\r\n});\r\n});\r\n});\r\n});<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">opening file<br \/>\nopened successfully!<br \/>\ntruncating the file after 10 bytes<br \/>\ntruncated successfully.<br \/>\nreading the same file<br \/>\nWelcome to<br \/>\nclosed successfully.<\/div>\n<h3>Node.js File Information:<\/h3>\n<p>fs.stat method is used to get the details about the file. We pass the file path in the fs.stat method of the file system module.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>fs.stat(path, callback)<\/p>\n<p><strong>Parameter:<\/strong><\/p>\n<p>Path: file name including path.<br \/>\nCallback: callback function gets two arguments (err, stats)<\/p>\n<h3>Node.js fs.Stats:<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">stats.isfile()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a simple file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.isdirectory()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a directory.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.isblockdevice()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a block device.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.ischaracterdevice()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a character device.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.issymboliclink()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a symbolic link.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.isfifo()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is a fifo.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">stats.issocket()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns true when the file type is socket.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Flags for read or write operations:<\/h3>\n<ul>\n<li>r:open for reading a file.<\/li>\n<li>r+ opening for reading and writing.<\/li>\n<li>rs: open reading in synchronous mode.<\/li>\n<li>Rs+:open writing and reading in synchronous mode<\/li>\n<li>w: open for writing a file.<\/li>\n<li>wx: writing but fails if path exists<\/li>\n<li>w+ opening for reading and writing.<\/li>\n<li>Wx:similar to w+ but fails if path exists<\/li>\n<li>a:open for appending a file.<\/li>\n<li>ax:similar to a but fails if path exists<\/li>\n<li>a+:open file for reading and appending<\/li>\n<li>ax+:similar to ax+ but fails if path exists<\/li>\n<\/ul>\n<h3>Important node js modules:<\/h3>\n<ul>\n<li>fs.chown(path, uid, gid, callback):Asynchronous chown.<\/li>\n<li>fs.link(srcpath, dstpath, callback):Links the given file.<\/li>\n<li>fs.symlink(destination, path[, type], callback):Symlink asynchronously.<\/li>\n<li>fs.rmdir(path, callback):Rename a directory.<\/li>\n<li>fs.mkdir(path[, mode], callback):Create a directory.<\/li>\n<li>fs.readdir(path, callback):Read the content from the directory.<\/li>\n<li>fs.exists(path, callback):checks if file exists or not.<\/li>\n<li>fs.access(path[, mode], callback):Tests a user&#8217;s permissions for the<\/li>\n<li>specified file<\/li>\n<\/ul>\n<h3>Conclusion:<\/h3>\n<p>We have seen the different methods for creating and updating a file, we have also seen how to open a file, read a file, delete a file, and also rename a file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nodejs has a builtin module for the file system. We will be using this to perform various operations on files like creating, updating, renaming, deleting etc. So let&#8217;s start!!! Nodejs Create File: It has&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":103976,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25259],"tags":[25792],"class_list":["post-103553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js-tutorials","tag-nodejs-file-system"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>NodeJS File System - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about Nodejs File system. See different methods to create, update, open, read, delete, and also rename a file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NodeJS File System - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about Nodejs File system. See different methods to create, update, open, read, delete, and also rename a file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-01T03:30:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-01T06:56:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"NodeJS File System - DataFlair","description":"Learn about Nodejs File system. See different methods to create, update, open, read, delete, and also rename a file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/","og_locale":"en_US","og_type":"article","og_title":"NodeJS File System - DataFlair","og_description":"Learn about Nodejs File system. See different methods to create, update, open, read, delete, and also rename a file.","og_url":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-12-01T03:30:47+00:00","article_modified_time":"2021-12-01T06:56:07+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"NodeJS File System","datePublished":"2021-12-01T03:30:47+00:00","dateModified":"2021-12-01T06:56:07+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/"},"wordCount":1103,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp","keywords":["Nodejs file system"],"articleSection":["Node Js Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/","url":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/","name":"NodeJS File System - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp","datePublished":"2021-12-01T03:30:47+00:00","dateModified":"2021-12-01T06:56:07+00:00","description":"Learn about Nodejs File system. See different methods to create, update, open, read, delete, and also rename a file.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/nodejs-file-system\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/nodejs-file-system.webp","width":1200,"height":628,"caption":"nodejs file system"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/nodejs-file-system\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Node Js Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/node-js-tutorials\/"},{"@type":"ListItem","position":3,"name":"NodeJS File System"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/103553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=103553"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/103553\/revisions"}],"predecessor-version":[{"id":103987,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/103553\/revisions\/103987"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/103976"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=103553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=103553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=103553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}