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 tag is a block element?
<div> <img> <span>
<div>Web Programming and Development</div>
Which CSS code displays the text underlined?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
}
Click on the JavaScript function that can access other function after a specified time.
insertBefore() setTimeout() querySelector()
function someFunction() { alert("CoursesWeb.net"); }
setTimeout("someFunction()", 2000);
Click on the instruction that returns the number of items of a multidimensional array in PHP.
count($array) count($array, 1) strlen()
$food =["fruits" =>["banana", "apple"), "veggie" =>["collard", "pea"));
$nr_food = count($food, 1);
echo $nr_food;       // 6
Node.js Move and Copy Directory

Last accessed pages

  1. Blade Templates - Control Structures (725)
  2. Align DIVs on the same line (8470)
  3. Shape Tween - Flash Animation (6153)
  4. Classic Tween - Flash Animation (6146)
  5. The Stage, Panels and Tools in Flash (10359)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (583)
  2. The Mastery of Love (92)
  3. CSS cursor property - Custom Cursors (92)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (68)
  5. Read Excel file data in PHP - PhpExcelReader (54)