OSD600_lab1

Requirements


This lab will introduce you to blogging, the CDOT wiki, and node's fs module. Here is a checklist of what needs to be done (see below for more details):

  • Create a CDOT wiki account
  • Create a Blog account
  • Add your Blog's RSS Feed URL to the CDOT Wiki's Planet Feed List
  • Research a node.js fs module feature
  • Write a short post about how to use this feature in the various supported
  • Add your Name and Blog post's URL to the table at the end of this lab

Research a node.js fs feature



1.

/***************************************************************************
 *  fs.unlink(path, callback)                                                                                                 
 *  This method is used to delete a file asynchronously.                                                           
 *  Here is the description of the parameters used :                                                                     
 *     .path       − This is the file name including path.                                                                 
 *     .callback − This is the callback function No arguments other than a possible exception   
 *                       are given to the completion callback.                                                                
****************************************************************************/                                                                                                              
//File name: deleteFile.js

//include node fs module
var fs = require('fs');


console.log("Going to delete an existing file");
//delete file named 'input.txt'
fs.unlink('input.txt', function(err) {
   if (err) {
      return console.error(err);
   }
   console.log("File deleted successfully!");
});

//Run the deleteFile.js to see the result:
//$node deleteFile.js

//Output:
//Going to delete an existing file
//File deleted successfully!

2.
/***************************************************************************
 *  fs.unlinkSync(path, callback)                                                                                              
 *  This method is used to delete a file synchronously. This function makes sure that file is 
 *    deleted (if it exits) before the execution of subsequent statement .                                  
 *  Here is the description of the parameters used :                                                                     
 *     .path       − This is the file name including path.                                                                 
 * 
****************************************************************************/                                                                                                                                                                             
//File name: deleteFileSynchronoudly.js


//include node fs module
var fs = require('fs');


console.log("Going to delete an existing file");
//delete file named 'input.txt' Synchronously
fs.unlinkSync('input.txt')
console.log("File deleted successfully!");


//Run the deleteFileSynchronoudly.js to see the result:
//$node deleteFileSynchronoudly.js

//Output:
//Going to delete an existing file
//File deleted successfully!


3.

fsPromise.unlink()
https://nodejs.org/api/fs.html#fs_fspromises_unlink_path

4.

What is callback? / Blocking code example? / Non-blocking code example?

If you are interesting these questions above, please click the link below for the reference
https://www.tutorialspoint.com/nodejs/nodejs_callbacks_concept.htm


References
https://wiki.cdot.senecacollege.ca/wiki/DPS909/OSD600_Fall_2018_Lab_1
https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback
https://nodejs.org/api/fs.html#fs_fs_unlinksync_path
https://nodejs.org/api/fs.html#fs_fspromises_unlink_path
https://www.tutorialspoint.com/nodejs/nodejs_callbacks_concept.htm
https://www.tutorialkart.com/nodejs/delete-a-file-in-nodejs-using-node-fs/
https://www.tutorialspoint.com/nodejs/nodejs_file_system.htm

Comments

Post a Comment

Popular posts from this blog

release0.3_summary

OSD600-Release0.4-PR2-blog2