Hot Article
- Centos7 closes and restarts the system firewall and opens firewall ports
- How IID server uses Xshell to connect to Linux (centos) server
- BT panel forgets the background login URL, and the solution to the security entrance verification failure
- The php domain name points to ip, how to use the specified ip address to access a server in the url request domain name in curl mode
- How to purchase a dedicated server
- Error connecting to MySQL: Cant connect to MySQL server (10060)
IDGlobal teaches you how to create folders in node.js
- Author:Sven
- Category:Website building
- Release Time:2022-11-29
Generally, for the copy operation of small files, the pipeline transportation operation of stream is used,
First you need to load the imported files:
var fs = require('fs');
1. Create folders synchronously
fs.mkdirSync(yourfileDirPath);
Create folder asynchronously
fs.mkdir(yourfileDirPath);
2. Determine whether the folder exists—synchronization
fs.existsSync(dirpath);
Asynchronous
fs. exists(dirpath);
Using the above related operations, we can directly write a method to determine the creation of a folder,
function mkdir(dirpath,dirname) {
//Determine that the second parameter can not be passed in
//Judge whether the second parameter is normal, avoid passing in wrong parameters when calling
if (dirname !== path.dirname(dirpath)) {
mkdir(dirpath);
return;
}
if (fs. existsSync(dirname)) {
fs.mkdirSync(dirpath)
} else {
mkdir(dirname, path.dirname(dirname));
fs.mkdirSync(dirpath);
}
}
Pay attention to synchronous and asynchronous creation, reading and other issues, otherwise the folder does not exist when copying, it is recommended to use the synchronous creation Sync method, generally in the form of fs.xxxSync
The above is all the content about the method of creating folders in node.js. After understanding, I believe everyone can find out the problem. If you want to know more about technology, please pay attention to INTERNET DATA.
related topic
- IDGlobal teaches you how to create folders in node.js
- How to set up scheduled website data backup on the IDGlobal pagoda panel
- How to import the SSL certificate (pfx) and how to bind to the specified website.
- Guardian host master Linux add binding ssl certificate graphic tutorial
- How to build a website on a cloud server? Practical construction of video website graphic tutorial
- How IID server uses Xshell to connect to Linux (centos) server