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
What attribute makes a radio button or checkbox input selected?
checked="checked" selected="selected" disabled="disabled"<input type="checkbox" name="a_name" value="value" checked="checked" />
What CSS value scales the background image to the largest size contained within the element?
repeat-x contain linear-gradient#id {
background:url("path_to_image.png");
background-size:contain;
background-repeat:no-repeat;
}
What operator is used to determine the rest of the division of two numbers?
% * /var rest8_7 = 8 % 7;
alert(rest8_7);
Indicate the PHP function that rounds a number up to the next highest integer.
floor() ceil() abs()$nr = ceil(3.5);
echo $nr; // 4