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 attribute specifies the HTTP method (GET, POST) used to submit the form-data?
action method value
<form action="script.php" method="post"> ... </form>
Which CSS property allows to add shadow to boxes?
background-image box-shadow border-radius
#id {
  background-color: #bbfeda;
  box-shadow: 11px 11px 5px #7878da;
}
Which function removes the first element from an array?
pop() push() shift()
var fruits = ["apple", "apricot", "banana"];
fruits.shift();
alert(fruits.length);           // 2
Indicate the function that can be used to check if a PHP extension is instaled.
function() filetype() extension_loaded()
if(extension_loaded("PDO") === true) echo "PDO is available."
Node.js Move and Copy Directory

Last accessed pages

  1. PHP Script Website Mini-Traffic (7281)
  2. innerHTML and outerHTML to Get and Replace HTML content (30658)
  3. Mysql SELECT JOIN tables on two different Databases (4523)
  4. Date and Time in ActionScript 3 (10112)
  5. CSS Trapezoid Shape (11425)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (120)
  2. CSS cursor property - Custom Cursors (13)
  3. PHP Unzipper - Extract Zip, Rar Archives (13)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (12)
  5. JavaScript trim, rtrim and ltrim (11)