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

More from Lovely Professional University

Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Lovely Professional University
 
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Lovely Professional University
 
Programme Management & Project Evaluation
Programme Management & Project EvaluationProgramme Management & Project Evaluation
Programme Management & Project Evaluation
Lovely Professional University
 
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Lovely Professional University
 
Introduction to Software Project Management:
Introduction to Software Project Management:Introduction to Software Project Management:
Introduction to Software Project Management:
Lovely Professional University
 
The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup language
Lovely Professional University
 
Working with JSON
Working with JSONWorking with JSON
Yargs Module
Yargs ModuleYargs Module
NODEMON Module
NODEMON ModuleNODEMON Module
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
Lovely Professional University
 
Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
Lovely Professional University
 
web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
Lovely Professional University
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
Lovely Professional University
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
Lovely Professional University
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
Lovely Professional University
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
Lovely Professional University
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
Lovely Professional University
 
Deploying your app.pptx
Deploying your app.pptxDeploying your app.pptx
Deploying your app.pptx
Lovely Professional University
 

More from Lovely Professional University (20)

Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
 
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
 
Programme Management & Project Evaluation
Programme Management & Project EvaluationProgramme Management & Project Evaluation
Programme Management & Project Evaluation
 
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
 
Introduction to Software Project Management:
Introduction to Software Project Management:Introduction to Software Project Management:
Introduction to Software Project Management:
 
The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup language
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Yargs Module
Yargs ModuleYargs Module
Yargs Module
 
NODEMON Module
NODEMON ModuleNODEMON Module
NODEMON Module
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
 
web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Web Server.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
 
Deploying your app.pptx
Deploying your app.pptxDeploying your app.pptx
Deploying your app.pptx
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

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’); });