1.

Can you describe a few commands of working in the file system  from your local machine or database?

Answer»

Node.js file SYSTEM module is capable to work on file either on your local system or database but working on file system we have to call require() method for calling a file server. This can be understood by the following example:- 

Var fs = require(‘fs’); 

Basic activities or operations which are required for working on file are as mentioned below:- 

  • Read a file :- We have to call/use fs.readFile() method for reading any file on our local system or any HTTP file. For example:- 
var http = require('http');  var fs = require('fs');  http.createServer(function (REQ, res) {    fs.readFile('demofile1.html', function(err, data) {      res.writeHead(200, {'Content-Type': 'text/html'});  res.write(data);      res.end();    });  }).listen(8080);  
  • Create a file:- For creating any new file we have three different METHODS which are as follows:-  fs.appendFile(); 
    fs.open();      fs.writeFile();
  • UPDATE a file:- For creating any new file we have two different methods which are as follows:- fs.appendFile(); 
   fs.writeFile(); 
  • Delete a file:- For deleting any file with file system module we have to use the following method:- fs.unlink() 
  • Rename a file:- For renaming any file with file system module we have to use the following method:- fs.rename() 


Discussion

No Comment Found