fs.copyFile


fs.CopyFile


     Uses:


     Copying a file from one location to another,
     By default, dest is overwritten if open if it Exists 

     Setup:

        To get started I setup a simple server that would just run our js code. Since we're also testing             CopyFile I created a source file source.txt that is a simple text list.



LIST:

Sir John Alexander Macdonald
Alexander Mackenzie
Sir John Alexander Macdonald
Sir John Abbott
Sir John Thompson
Sir Mackenzie Bowell
Sir Charles Tupper
Sir Wilfrid Laurier
Sir Robert Laird Borden
Arthur Meighen
W.L. Mackenzie King
Arthur Meighen
W.L. Mackenzie King
Richard Bedford Bennett
W.L. Mackenzie King
Louis Saint Laurent
John G. Diefenbaker
Lester B. Pearson
Pierre Elliott Trudeau
Joe Clark
Pierre Elliott Trudeau
John N. Turner
Brian Mulroney
Kim Campbell
Jean Chrétien
Paul Martin
Stephen Harper
Justin Trudeau



     Use Case 1:  Copying a List,

       Copy a simple text list should be easy, lets fire up our server with node and see what happens!

        node server.js


       The List is even correctly formatted, great! Now lets try and do it again but lets add a flag so it doesn't overwrite the file! This is done by adding 1 line into the method call

        fs.constants.COPYFILE_EXCL


    When we run it again with this change, we can see that an err gets thrown!



 Use Case 2: Backing up Files

    For this case I wanted to just have a simple backup happen upon an action, I created an express server and just had it backup the html files when the server launches, Making the name variables  combines with date() would allow for a great catalog of back-ups



 Now when we launch we can see that the launch back-up completes along with an entry into our backup folder.

  Use Case 3: Backing up School work along with updating a page

   I wanted to make something that would be useful to me currently. In another class we have a vm that we have to manage along with hosting files that we've been working on. Therefore I wanted to create a way to backup those file and or refresh old versions of html. So first I setup sftp in javascript

npm install ssh2-sftp-client


With Some basic usage.



























Here we see that I grab my index from the server, store it according to date along with refresh the current index.html on the current system. This could be setup on heroku on a timer and would / could keep all data from my teams vm backed up.












Comments

Popular posts from this blog

Image-Steganography-Library-Android

Release 0.2

Release 0.3