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