SlideShare ist ein Scribd-Unternehmen logo
1 von 19
iFour ConsultancyNode File System
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Node.js gives the functionality of File I/O by providing wrappers around the
standard POSIX functions. In Node.js, File I/O methods can be performed in both
synchronous as well as asynchronous form depending upon the user requirements.
 The Node.js file system module allows you to work with the file system on your
computer.
 To include the File System module, use the require() method:
var fs = require('fs');
Introduction
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Common use for the File System module:
1. Read files
2. Write files
3. Append files
4. Delete files
5. Rename files
Use of File System
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Every method in the fs module has synchronous as well as asynchronous forms.
Asynchronous methods take the last parameter as the completion function callback
and the first parameter of the callback function as error. It is better to use an
asynchronous method instead of a synchronous method, as the former never
blocks a program during its execution, whereas the second one does.
Synchronous vs Asynchronous
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Every method in fs module has synchronous and asynchronous forms.
 Asynchronous methods take a last parameter as completion function callback.
Asynchronous method is preferred over synchronous method because it never
blocks the program execution where as the synchronous method blocks.
 Example:
Create File: input.txt
We are reading this file using node.js
Node.js Reading File
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Example: Create File main.js
For Asynchronous read :
var fs = require("fs");
// Asynchronous read
fs.readFile('input.txt', function (err, data) {
if (err) {
return console.error(err);
}
console.log("Asynchronous read: " + data.toString());
Node.js Reading File
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Example: Create File main.js
For Synchronous read :
var data = fs.readFileSync('input.html');
console.log("Synchronous read: " + data.toString());
console.log("Program Ended");
 Open command prompt and run the main.js:
> node main.js
Node.js Reading File
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 Node.js fs.writeFile() function writes data to a file asynchronously with replacing
the file in case of already exists. This function can write data from string or a buffer.
 The encoding option is ignored if data is a buffer. It defaults encoding is ‘utf8’,
Default file mode is 0666 and default flag is used ‘w’ means write mode.
1. path is the filename with path.
2. data is the String or buffer to write
3. options can be an object which is like {encoding, mode, flag}.
4. callback function takes single parameter err and used to return errors.
 Syntax:
fs.writeFile(filename, data[, options], callback)
Node.js Writing a file
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Node.js Writing a file
 There are two ways for writing a file in nodejs :
 Example: Create File main.js
For Asynchronous Write :
var fs = require('fs');
var content= "this is the content in the file";
fs.writeFile('input.txt', content , (err) => {
if (err)
throw err;
console.log('It's saved!');
});
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Node.js Writing a file
 Example: Create File main.js
For Synchronous write :
var fs = require('fs');
var content = "We are writing this file synchronously using
node.js";
fs.writeFileSync('input.txt', content);
console.log("File Written Successfully");
 Open command prompt and run the main.js:
> node main.js
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 To append data to file in Node.js, use Node FS appendFile() function for
asynchronous file operation or Node FS appendFileSync() function for synchronous
file operation.
filepath is a String that specifies file path
data is what you append to the file
options to specify encoding/mode/flag
 Syntax:
fs.appendFile(filepath, data, options, callback_function);
fs.appendFileSync(filepath, data, options);
Append a File using Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 There are two ways for Appending a file using nodejs :
 Example: Create File main.js
For Asynchronous Append :
var fs = require('fs');
new_data = "This data will be appended at the end of the file.";
fs.appendFile('input.txt', new_data , (err) => {
if(err)
throw err;
console.log('The new_content was appended successfully');
});
Append a File using Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Append a File using Nodejs
Example: Create File main.js
For Synchronous Append :
var fs = require('fs');
var content = "We are Appending this file synchronously using node.js";
fs.appendFileSync('input.txt', content);
console.log("File Appended Successfully");
 Open command prompt and run the main.js:
> node main.js
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 To rename file with Node FS, use fs.rename(new_file_name, old_file_name,
callback_function) for asynchronous file rename operation and use
fs.renameSync(new_file_name, old_file_name) for synchronous file rename
operation.
new_file_path : The new file path you would like to assign
old_file_path : Path to the file whose name is to be changed
callback_function : When file renaming operation is done, Callback Function is
called with an error object.
 Syntax:
fs.rename(new_file_path, old_file_path, callback_function)
fs.renameSync(new_file_path, old_file_path)
Rename a File in Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 There are two ways for Appending a file using nodejs :
 Example: Create File main.js
For Asynchronous Rename :
var fs = require('fs');
fs.rename('input.txt', 'newinput.txt', (err) => {
if (err)
throw err;
console.log('File renamed successfully');
});
console.log("This method is Asynchronous");
Rename a File in Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Example: Create File main.js
For Synchronous Rename :
var fs = require('fs');
fs.renameSync('input.txt', 'newinput.txt');
console.log('File renamed successfully');
console.log("This method is Synchronous");
 Open command prompt and run the main.js:
> node main.js
Rename a File in Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
 To delete a file in Node.js, Node FS unlink(path, callback) can be used for
asynchronous file operation and unlinkSync(path) can be used for synchronous file
operation.
 Syntax:
fs.unlink(filePath, callbackFunction)
fs.unlinkSync(filePath)
Delete a File in Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Delete a File in Nodejs
 There are two ways for Appending a file using nodejs :
 Example: Create File main.js
For Asynchronous Delete :
var fs = require('fs');
var filename = 'input.txt';
fs.unlink(filename, (err) => {
if (err)
throw err;
console.log('File deleted successfully');
});
https://www.ifourtechnolab.com/nodejs-blockchain-software-development
Example: Create File main.js
For Synchronous Delete:
var fs = require('fs');
var filename = 'input.txt';
fs.unlinkSync(filename);
console.log('File Deleted Successfully');
 Open command prompt and run the main.js:
> node main.js
Delete a File in Nodejs
https://www.ifourtechnolab.com/nodejs-blockchain-software-development

Weitere ähnliche Inhalte

Was ist angesagt?

Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testingGaruda Trainings
 
Integration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSIntegration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSChristophe Marchal
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHPfwso
 
WebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUpWebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUphuguk
 
It’s about time to embrace Streams
It’s about time to embrace StreamsIt’s about time to embrace Streams
It’s about time to embrace StreamsLuciano Mammino
 
Archlinux install
Archlinux installArchlinux install
Archlinux installsambismo
 
리눅스 간단 강의 5강
리눅스 간단 강의 5강리눅스 간단 강의 5강
리눅스 간단 강의 5강Junsu Kim
 
Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9David Calavera
 
Web scraping with nutch solr part 2
Web scraping with nutch solr part 2Web scraping with nutch solr part 2
Web scraping with nutch solr part 2Mike Frampton
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ublnewrforce
 

Was ist angesagt? (19)

Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
Integration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSIntegration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFS
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
Android APP-toggle case
Android APP-toggle caseAndroid APP-toggle case
Android APP-toggle case
 
File Upload
File UploadFile Upload
File Upload
 
MongoDB & PHP
MongoDB & PHPMongoDB & PHP
MongoDB & PHP
 
WebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUpWebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUp
 
It’s about time to embrace Streams
It’s about time to embrace StreamsIt’s about time to embrace Streams
It’s about time to embrace Streams
 
Archlinux install
Archlinux installArchlinux install
Archlinux install
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
리눅스 간단 강의 5강
리눅스 간단 강의 5강리눅스 간단 강의 5강
리눅스 간단 강의 5강
 
Dns
DnsDns
Dns
 
Caching. api. http 1.1
Caching. api. http 1.1Caching. api. http 1.1
Caching. api. http 1.1
 
Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9Rubyspec y el largo camino hacia Ruby 1.9
Rubyspec y el largo camino hacia Ruby 1.9
 
Fluentd and WebHDFS
Fluentd and WebHDFSFluentd and WebHDFS
Fluentd and WebHDFS
 
Http
HttpHttp
Http
 
Web scraping with nutch solr part 2
Web scraping with nutch solr part 2Web scraping with nutch solr part 2
Web scraping with nutch solr part 2
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Rhel1
Rhel1Rhel1
Rhel1
 

Ähnlich wie Tutorial on Node File System

Ähnlich wie Tutorial on Node File System (20)

File System in Nodejs.pdf
File System in Nodejs.pdfFile System in Nodejs.pdf
File System in Nodejs.pdf
 
File System.pptx
File System.pptxFile System.pptx
File System.pptx
 
Requiring your own files.pptx
Requiring your own files.pptxRequiring your own files.pptx
Requiring your own files.pptx
 
PHP File Handling
PHP File Handling PHP File Handling
PHP File Handling
 
FS_module_functions.pptx
FS_module_functions.pptxFS_module_functions.pptx
FS_module_functions.pptx
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.js
 
File system node js
File system node jsFile system node js
File system node js
 
data file handling
data file handlingdata file handling
data file handling
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Php advance
Php advancePhp advance
Php advance
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Introduction to Node JS1.pdf
Introduction to Node JS1.pdfIntroduction to Node JS1.pdf
Introduction to Node JS1.pdf
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Node36
Node36Node36
Node36
 
Php BASIC
Php BASICPhp BASIC
Php BASIC
 
Kevin Schmidt - Uploading Files in Flex
Kevin Schmidt - Uploading Files in FlexKevin Schmidt - Uploading Files in Flex
Kevin Schmidt - Uploading Files in Flex
 
Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game projectIntroduction to Node js for beginners + game project
Introduction to Node js for beginners + game project
 
Best Practices For Direct Admin Security
Best Practices For Direct Admin SecurityBest Practices For Direct Admin Security
Best Practices For Direct Admin Security
 
Files nts
Files ntsFiles nts
Files nts
 

Mehr von iFour Technolab Pvt. Ltd.

Software for Physiotherapists (+Physio) - Final.pdf
Software for Physiotherapists (+Physio) - Final.pdfSoftware for Physiotherapists (+Physio) - Final.pdf
Software for Physiotherapists (+Physio) - Final.pdfiFour Technolab Pvt. Ltd.
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfiFour Technolab Pvt. Ltd.
 
iFour Technolab - .NET Development Company Profile
iFour Technolab - .NET Development Company ProfileiFour Technolab - .NET Development Company Profile
iFour Technolab - .NET Development Company ProfileiFour Technolab Pvt. Ltd.
 
Meetup - IoT with Azure behind the scenes 2022.pptx
Meetup - IoT with Azure behind the scenes 2022.pptxMeetup - IoT with Azure behind the scenes 2022.pptx
Meetup - IoT with Azure behind the scenes 2022.pptxiFour Technolab Pvt. Ltd.
 
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022iFour Technolab Pvt. Ltd.
 
Complete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour TechnolabComplete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour TechnolabiFour Technolab Pvt. Ltd.
 
ASP Dot Net Software Development in India - iFour Technolab
ASP Dot Net Software Development in India - iFour TechnolabASP Dot Net Software Development in India - iFour Technolab
ASP Dot Net Software Development in India - iFour TechnolabiFour Technolab Pvt. Ltd.
 
Basic Introduction of VSTO Office Add-in Software Development - iFour Technolab
Basic Introduction of VSTO Office Add-in Software Development - iFour TechnolabBasic Introduction of VSTO Office Add-in Software Development - iFour Technolab
Basic Introduction of VSTO Office Add-in Software Development - iFour TechnolabiFour Technolab Pvt. Ltd.
 
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.iFour Technolab Pvt. Ltd.
 
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.iFour Technolab Pvt. Ltd.
 
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.iFour Technolab Pvt. Ltd.
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)iFour Technolab Pvt. Ltd.
 
MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutioniFour Technolab Pvt. Ltd.
 
Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)iFour Technolab Pvt. Ltd.
 

Mehr von iFour Technolab Pvt. Ltd. (20)

Software for Physiotherapists (+Physio) - Final.pdf
Software for Physiotherapists (+Physio) - Final.pdfSoftware for Physiotherapists (+Physio) - Final.pdf
Software for Physiotherapists (+Physio) - Final.pdf
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdf
 
iFour Technolab - .NET Development Company Profile
iFour Technolab - .NET Development Company ProfileiFour Technolab - .NET Development Company Profile
iFour Technolab - .NET Development Company Profile
 
Java9to19Final.pptx
Java9to19Final.pptxJava9to19Final.pptx
Java9to19Final.pptx
 
Meetup - IoT with Azure behind the scenes 2022.pptx
Meetup - IoT with Azure behind the scenes 2022.pptxMeetup - IoT with Azure behind the scenes 2022.pptx
Meetup - IoT with Azure behind the scenes 2022.pptx
 
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022
LAZY IS NEW SMART LET IoT HANDLE IT - Meet UP 2022
 
NFT_Meetup - iFour Technolab.pptx
NFT_Meetup - iFour Technolab.pptxNFT_Meetup - iFour Technolab.pptx
NFT_Meetup - iFour Technolab.pptx
 
Complete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour TechnolabComplete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour Technolab
 
ASP Dot Net Software Development in India - iFour Technolab
ASP Dot Net Software Development in India - iFour TechnolabASP Dot Net Software Development in India - iFour Technolab
ASP Dot Net Software Development in India - iFour Technolab
 
Basic Introduction and Overview of Vue.js
Basic Introduction and Overview of Vue.jsBasic Introduction and Overview of Vue.js
Basic Introduction and Overview of Vue.js
 
Basic Introduction of VSTO Office Add-in Software Development - iFour Technolab
Basic Introduction of VSTO Office Add-in Software Development - iFour TechnolabBasic Introduction of VSTO Office Add-in Software Development - iFour Technolab
Basic Introduction of VSTO Office Add-in Software Development - iFour Technolab
 
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Case in Legal Industry - iFour Technolab Pvt. Ltd.
 
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Healthcare Industry - iFour Technolab Pvt. Ltd.
 
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.
Blockchain Use Cases in Financial Services Industry - iFour Technolab Pvt. Ltd.
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & Execution
 
Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)Controls Use in Windows Presentation Foundation (WPF)
Controls Use in Windows Presentation Foundation (WPF)
 
Agile Project Management with Scrum PDF
Agile Project Management with Scrum PDFAgile Project Management with Scrum PDF
Agile Project Management with Scrum PDF
 
Understanding Agile Development with Scrum
Understanding Agile Development with ScrumUnderstanding Agile Development with Scrum
Understanding Agile Development with Scrum
 
Types of Non Functional Testing
Types of Non Functional TestingTypes of Non Functional Testing
Types of Non Functional Testing
 

Kürzlich hochgeladen

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Tutorial on Node File System

  • 1. iFour ConsultancyNode File System https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 2.  Node.js gives the functionality of File I/O by providing wrappers around the standard POSIX functions. In Node.js, File I/O methods can be performed in both synchronous as well as asynchronous form depending upon the user requirements.  The Node.js file system module allows you to work with the file system on your computer.  To include the File System module, use the require() method: var fs = require('fs'); Introduction https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 3.  Common use for the File System module: 1. Read files 2. Write files 3. Append files 4. Delete files 5. Rename files Use of File System https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 4.  Every method in the fs module has synchronous as well as asynchronous forms. Asynchronous methods take the last parameter as the completion function callback and the first parameter of the callback function as error. It is better to use an asynchronous method instead of a synchronous method, as the former never blocks a program during its execution, whereas the second one does. Synchronous vs Asynchronous https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 5.  Every method in fs module has synchronous and asynchronous forms.  Asynchronous methods take a last parameter as completion function callback. Asynchronous method is preferred over synchronous method because it never blocks the program execution where as the synchronous method blocks.  Example: Create File: input.txt We are reading this file using node.js Node.js Reading File https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 6.  Example: Create File main.js For Asynchronous read : var fs = require("fs"); // Asynchronous read fs.readFile('input.txt', function (err, data) { if (err) { return console.error(err); } console.log("Asynchronous read: " + data.toString()); Node.js Reading File https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 7.  Example: Create File main.js For Synchronous read : var data = fs.readFileSync('input.html'); console.log("Synchronous read: " + data.toString()); console.log("Program Ended");  Open command prompt and run the main.js: > node main.js Node.js Reading File https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 8.  Node.js fs.writeFile() function writes data to a file asynchronously with replacing the file in case of already exists. This function can write data from string or a buffer.  The encoding option is ignored if data is a buffer. It defaults encoding is ‘utf8’, Default file mode is 0666 and default flag is used ‘w’ means write mode. 1. path is the filename with path. 2. data is the String or buffer to write 3. options can be an object which is like {encoding, mode, flag}. 4. callback function takes single parameter err and used to return errors.  Syntax: fs.writeFile(filename, data[, options], callback) Node.js Writing a file https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 9. Node.js Writing a file  There are two ways for writing a file in nodejs :  Example: Create File main.js For Asynchronous Write : var fs = require('fs'); var content= "this is the content in the file"; fs.writeFile('input.txt', content , (err) => { if (err) throw err; console.log('It's saved!'); }); https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 10. Node.js Writing a file  Example: Create File main.js For Synchronous write : var fs = require('fs'); var content = "We are writing this file synchronously using node.js"; fs.writeFileSync('input.txt', content); console.log("File Written Successfully");  Open command prompt and run the main.js: > node main.js https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 11.  To append data to file in Node.js, use Node FS appendFile() function for asynchronous file operation or Node FS appendFileSync() function for synchronous file operation. filepath is a String that specifies file path data is what you append to the file options to specify encoding/mode/flag  Syntax: fs.appendFile(filepath, data, options, callback_function); fs.appendFileSync(filepath, data, options); Append a File using Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 12.  There are two ways for Appending a file using nodejs :  Example: Create File main.js For Asynchronous Append : var fs = require('fs'); new_data = "This data will be appended at the end of the file."; fs.appendFile('input.txt', new_data , (err) => { if(err) throw err; console.log('The new_content was appended successfully'); }); Append a File using Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 13. Append a File using Nodejs Example: Create File main.js For Synchronous Append : var fs = require('fs'); var content = "We are Appending this file synchronously using node.js"; fs.appendFileSync('input.txt', content); console.log("File Appended Successfully");  Open command prompt and run the main.js: > node main.js https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 14.  To rename file with Node FS, use fs.rename(new_file_name, old_file_name, callback_function) for asynchronous file rename operation and use fs.renameSync(new_file_name, old_file_name) for synchronous file rename operation. new_file_path : The new file path you would like to assign old_file_path : Path to the file whose name is to be changed callback_function : When file renaming operation is done, Callback Function is called with an error object.  Syntax: fs.rename(new_file_path, old_file_path, callback_function) fs.renameSync(new_file_path, old_file_path) Rename a File in Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 15.  There are two ways for Appending a file using nodejs :  Example: Create File main.js For Asynchronous Rename : var fs = require('fs'); fs.rename('input.txt', 'newinput.txt', (err) => { if (err) throw err; console.log('File renamed successfully'); }); console.log("This method is Asynchronous"); Rename a File in Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 16. Example: Create File main.js For Synchronous Rename : var fs = require('fs'); fs.renameSync('input.txt', 'newinput.txt'); console.log('File renamed successfully'); console.log("This method is Synchronous");  Open command prompt and run the main.js: > node main.js Rename a File in Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 17.  To delete a file in Node.js, Node FS unlink(path, callback) can be used for asynchronous file operation and unlinkSync(path) can be used for synchronous file operation.  Syntax: fs.unlink(filePath, callbackFunction) fs.unlinkSync(filePath) Delete a File in Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 18. Delete a File in Nodejs  There are two ways for Appending a file using nodejs :  Example: Create File main.js For Asynchronous Delete : var fs = require('fs'); var filename = 'input.txt'; fs.unlink(filename, (err) => { if (err) throw err; console.log('File deleted successfully'); }); https://www.ifourtechnolab.com/nodejs-blockchain-software-development
  • 19. Example: Create File main.js For Synchronous Delete: var fs = require('fs'); var filename = 'input.txt'; fs.unlinkSync(filename); console.log('File Deleted Successfully');  Open command prompt and run the main.js: > node main.js Delete a File in Nodejs https://www.ifourtechnolab.com/nodejs-blockchain-software-development

Hinweis der Redaktion

  1. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  2. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  3. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  4. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  5. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  6. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  7. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  8. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  9. Software Outsourcing Company India - http://www.ifourtechnolab.com/
  10. Software Outsourcing Company India - http://www.ifourtechnolab.com/