SlideShare a Scribd company logo
fs Module
Create Files
The File System module has methods for creating new files:
• fs.appendFile()
• fs.open()
• fs.writeFile()
fs.appendFile() method
The fs.appendFile() method appends specified content to a file. If the file
does not exist, the file will be created:
var fs = require('fs');
fs.appendFile(‘NodeJS.txt’, ‘Welcome to NodeJS Tutorial’, function
(err)
{
if (err) throw err;
console.log('Saved');
});
fs.open() method
The fs.open() method takes a "flag" as the second argument, if the flag
is "w" for "writing", the specified file is opened for writing. If the file
does not exist, an empty file is created.
var fs = require('fs');
fs.open(' NodeJS.txt', 'w', function (err, file)
{
if (err) throw err;
console.log('Saved!');
});
fs.writeFile() method
The fs.writeFile() method replaces the specified file and content if it
exists. If the file does not exist, a new file, containing the specified
content, will be created.
var fs = require('fs');
fs.writeFile(‘NodeJS.txt', ' Welcome to NodeJS Tutorial ',
function (err)
{
if (err) throw err;
console.log('Saved!');
});
Update Files
The File System module has methods for updating files:
• fs.appendFile()
• fs.writeFile()
fs.appendFile() method
The fs.appendFile() method appends the specified content at the end
of the specified file.
var fs = require(‘fs’);
fs.appendFile(‘NodeJS.txt’, ‘Mukesh Kumar’, function (err)
{
if (err) throw err;
console.log(‘Updated’);
});
fs.writeFile() method
The fs.writeFile() method replaces the specified file and content.
var fs = require(‘fs’);
fs.writeFile(‘NodeJS.txt’, ‘This is my text’, function (err)
{
if (err) throw err;
console.log(‘Replaced’);
});
Delete Files
To delete a file with the File System module, use the fs.unlink()
method.
fs.unlink() method
The fs.unlink() method deletes the specified file.
var fs = require(‘fs’);
fs.unlink(‘NodeJS.txt’, function (err)
{
if (err) throw err;
console.log(‘File deleted’);
});
Rename Files
To rename a file with the File System module, use the fs.rename()
method.
fs.rename() method
The fs.rename() method renames the specified file.
var fs = require(‘fs’);
fs.rename(‘NodeJS.txt’, ‘Mukesh.txt’, function (err)
{
if (err) throw err;
console.log(‘File Renamed’);
});

More Related Content

PPTX
FS_module_functions.pptx
Bareen Shaikh
 
PDF
File System in Nodejs.pdf
SudhanshiBakre1
 
PPTX
Requiring your own files.pptx
Lovely Professional University
 
PPTX
File system node js
monikadeshmane
 
PDF
Building a userspace filesystem in node.js
Clay Smith
 
PPTX
Tutorial on Node File System
iFour Technolab Pvt. Ltd.
 
PPTX
U4-01-Node JS.pptxweasrdtfyhg[]"Piuytrhedfyguhijokpl
vinodkumarthatipamul
 
PDF
node-fs
Bruno Pedro
 
FS_module_functions.pptx
Bareen Shaikh
 
File System in Nodejs.pdf
SudhanshiBakre1
 
Requiring your own files.pptx
Lovely Professional University
 
File system node js
monikadeshmane
 
Building a userspace filesystem in node.js
Clay Smith
 
Tutorial on Node File System
iFour Technolab Pvt. Ltd.
 
U4-01-Node JS.pptxweasrdtfyhg[]"Piuytrhedfyguhijokpl
vinodkumarthatipamul
 
node-fs
Bruno Pedro
 

Similar to fs Module.pptx (20)

PPTX
Hands On Intro to Node.js
Chris Cowan
 
PPTX
File System.pptx
Bareen Shaikh
 
PPTX
module node jsbhgnbgtyuikmnbvcfyum2.pptx
hemalathas752360
 
PDF
Top 30 Node.js interview questions
techievarsity
 
PDF
Node36
beshoy semsem
 
PDF
Streams in Node .pdf
SudhanshiBakre1
 
KEY
Node.js basics
Ben Lin
 
PDF
Learning a node stream
kumatch kumatch
 
PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
Kongu Engineering College, Perundurai, Erode
 
KEY
Node.js - A practical introduction (v2)
Felix GeisendĂśrfer
 
PPTX
Node JS Core Module PowerPoint Presentation
rajeshkannan750222
 
PDF
Nodejs - A-quick-tour-v3
Felix GeisendĂśrfer
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
PDF
Node JS | Dilkash Shaikh Mahajan
DilkashShaikhMahajan
 
PDF
Introduction to Node js for beginners + game project
Laurence Svekis ✔
 
PPTX
Getting Input from User
Lovely Professional University
 
PPTX
Unit-2 Getting Input from User.pptx
Lovely Professional University
 
PDF
Node intro
cloudhead
 
PDF
Global objects in Node.pdf
SudhanshiBakre1
 
PPT
Node.js
Pravin Mishra
 
Hands On Intro to Node.js
Chris Cowan
 
File System.pptx
Bareen Shaikh
 
module node jsbhgnbgtyuikmnbvcfyum2.pptx
hemalathas752360
 
Top 30 Node.js interview questions
techievarsity
 
Node36
beshoy semsem
 
Streams in Node .pdf
SudhanshiBakre1
 
Node.js basics
Ben Lin
 
Learning a node stream
kumatch kumatch
 
Node.js web-based Example :Run a local server in order to start using node.js...
Kongu Engineering College, Perundurai, Erode
 
Node.js - A practical introduction (v2)
Felix GeisendĂśrfer
 
Node JS Core Module PowerPoint Presentation
rajeshkannan750222
 
Nodejs - A-quick-tour-v3
Felix GeisendĂśrfer
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Node JS | Dilkash Shaikh Mahajan
DilkashShaikhMahajan
 
Introduction to Node js for beginners + game project
Laurence Svekis ✔
 
Getting Input from User
Lovely Professional University
 
Unit-2 Getting Input from User.pptx
Lovely Professional University
 
Node intro
cloudhead
 
Global objects in Node.pdf
SudhanshiBakre1
 
Node.js
Pravin Mishra
 
Ad

More from Lovely Professional University (20)

PPTX
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
PPTX
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Lovely Professional University
 
PPTX
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Lovely Professional University
 
PPTX
Programme Management & Project Evaluation
Lovely Professional University
 
PPTX
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Lovely Professional University
 
PPTX
Introduction to Software Project Management:
Lovely Professional University
 
PDF
The HyperText Markup Language or HTML is the standard markup language
Lovely Professional University
 
PPTX
Working with JSON
Lovely Professional University
 
PPTX
NODEMON Module
Lovely Professional University
 
PPTX
Transaction Processing in DBMS.pptx
Lovely Professional University
 
PPT
web_server_browser.ppt
Lovely Professional University
 
PPTX
Web Server.pptx
Lovely Professional University
 
PPTX
Number System.pptx
Lovely Professional University
 
PPT
Programming Language.ppt
Lovely Professional University
 
PPTX
Information System.pptx
Lovely Professional University
 
PPTX
Applications of Computer Science in Pharmacy-1.pptx
Lovely Professional University
 
PPTX
Application of Computers in Pharmacy.pptx
Lovely Professional University
 
PPTX
Deploying your app.pptx
Lovely Professional University
 
PPT
Setting up github and ssh keys.ppt
Lovely Professional University
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Lovely Professional University
 
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Lovely Professional University
 
Programme Management & Project Evaluation
Lovely Professional University
 
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Lovely Professional University
 
Introduction to Software Project Management:
Lovely Professional University
 
The HyperText Markup Language or HTML is the standard markup language
Lovely Professional University
 
Working with JSON
Lovely Professional University
 
Transaction Processing in DBMS.pptx
Lovely Professional University
 
web_server_browser.ppt
Lovely Professional University
 
Number System.pptx
Lovely Professional University
 
Programming Language.ppt
Lovely Professional University
 
Information System.pptx
Lovely Professional University
 
Applications of Computer Science in Pharmacy-1.pptx
Lovely Professional University
 
Application of Computers in Pharmacy.pptx
Lovely Professional University
 
Deploying your app.pptx
Lovely Professional University
 
Setting up github and ssh keys.ppt
Lovely Professional University
 
Ad

Recently uploaded (20)

PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Software Development Company | KodekX
KodekX
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Software Development Methodologies in 2025
KodekX
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Software Development Company | KodekX
KodekX
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Doc9.....................................
SofiaCollazos
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 

fs Module.pptx

  • 2. Create Files The File System module has methods for creating new files: • fs.appendFile() • fs.open() • fs.writeFile()
  • 3. fs.appendFile() method The fs.appendFile() method appends specified content to a file. If the file does not exist, the file will be created: var fs = require('fs'); fs.appendFile(‘NodeJS.txt’, ‘Welcome to NodeJS Tutorial’, function (err) { if (err) throw err; console.log('Saved'); });
  • 4. fs.open() method The fs.open() method takes a "flag" as the second argument, if the flag is "w" for "writing", the specified file is opened for writing. If the file does not exist, an empty file is created. var fs = require('fs'); fs.open(' NodeJS.txt', 'w', function (err, file) { if (err) throw err; console.log('Saved!'); });
  • 5. fs.writeFile() method The fs.writeFile() method replaces the specified file and content if it exists. If the file does not exist, a new file, containing the specified content, will be created. var fs = require('fs'); fs.writeFile(‘NodeJS.txt', ' Welcome to NodeJS Tutorial ', function (err) { if (err) throw err; console.log('Saved!'); });
  • 6. Update Files The File System module has methods for updating files: • fs.appendFile() • fs.writeFile()
  • 7. fs.appendFile() method The fs.appendFile() method appends the specified content at the end of the specified file. var fs = require(‘fs’); fs.appendFile(‘NodeJS.txt’, ‘Mukesh Kumar’, function (err) { if (err) throw err; console.log(‘Updated’); });
  • 8. fs.writeFile() method The fs.writeFile() method replaces the specified file and content. var fs = require(‘fs’); fs.writeFile(‘NodeJS.txt’, ‘This is my text’, function (err) { if (err) throw err; console.log(‘Replaced’); });
  • 9. Delete Files To delete a file with the File System module, use the fs.unlink() method.
  • 10. fs.unlink() method The fs.unlink() method deletes the specified file. var fs = require(‘fs’); fs.unlink(‘NodeJS.txt’, function (err) { if (err) throw err; console.log(‘File deleted’); });
  • 11. Rename Files To rename a file with the File System module, use the fs.rename() method.
  • 12. fs.rename() method The fs.rename() method renames the specified file. var fs = require(‘fs’); fs.rename(‘NodeJS.txt’, ‘Mukesh.txt’, function (err) { if (err) throw err; console.log(‘File Renamed’); });