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 HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas><embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line#id:first-line {
font-weight: bold;
color: blue;
}
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.statusvar url = window.location;
alert(url);
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()$homepage = file_get_contents("http://coursesweb.net/");
echo $homepage;