Nodejs Course

To easily work with directories and files on server, use the fs-extra module.
It can be a drop in replacement for "fs" build-in module.
- Before using the "fs-extra" module, you have to install it. To install "fs-extra", run this code in command line interface:
npm install --save fs-extra
Then, you can use the fs-extra module in your Node.js projects, as a drop in replacement for native fs.
const fs = require('fs-extra');

Moving directory

A simple way to move a directory in Node.js it is to use the fs.move(oldPath, newPath, callback) method of the fs-extra module.
- Example: move 'dir_2/' directory from 'test/' to 'dirx/':
const fs = require('fs-extra');

fs.move('./test/dir_2/', './dirx/dir_2/', err => {
  if(err) return console.error(err);
  console.log('success!');
});

Copy directory

To copy a directory in Node.js, you can use the copy() method of the fs-extra module.
Example: Copy the 'dir_2/' directory from 'test/' to 'dirx/':
const fs = require('fs-extra');

fs.copy('./test/dir_2/', './dirx/dir_2/', err =>{
  if(err) return console.error(err);
  console.log('success!');
});

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which meta tag provides a short description of the page?
<meta content="..."> <meta description="..."> <meta http-equiv="...">
<meta name="description" content="70-160 characters that describes the content of the page" />
Which CSS property is used to stop the wrapping effect of the "float"?
clear text-align position
#some_id {
  clear: both;
}
Click on the method which gets an array with all the elements in the document that have a specified tag name.
getElementsByName() getElementById() getElementsByTagName()
var divs = document.getElementsByTagName("div");
var nr_divs = divs.length;
alert(nr_divs);
Indicate the PHP function which returns the number of elements in array.
is_[) count() strlen()
$arr =[7, 8, "abc", 10);
$nri = count($arr);
echo $nri;        // 4
Node.js Move and Copy Directory

Last accessed pages

  1. AJAX with POST and PHP (18849)
  2. JQZoom Image Magnifier (12975)
  3. Change CSS file with jQuery (5381)
  4. JavaScript Course - Free lessons (31411)
  5. Properties and Methods of the Form elements (594)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (201)
  2. Read Excel file data in PHP - PhpExcelReader (66)
  3. The Mastery of Love (56)
  4. PHP Unzipper - Extract Zip, Rar Archives (51)
  5. Working with MySQL Database (34)
Chat
Chat or leave a message for the other users
Full screenInchide