“Knoten, wenn die Datei vorliegt” Code-Antworten

Knotenüberprüfung, ob die Datei vorliegt

const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
    // Do something
}
Witty Worm

Knoten, wenn die Datei vorliegt

const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
    // Do something
}
gaz_edge

Die NodeJS -Datei gibt es

const fs = require('fs')
// We will convert sync function into a promise function
// so when is ready will provide the result without blocking.
const exists = async (path) => {
	return await new Promise((resolve) => {
		resolve(fs.existsSync(path));
	});
};
// If you have a file name samples on same root it will result true.
exists('./samples.txt').then(res => console.log(res))
console.log(`I'm not blocked as I'll show up on first`)
God Of Coding

Überprüfen Sie, ob die Datei JavaScript vorliegt

function executeIfFileExist(src, callback) {
    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = function() {
        if (this.readyState === this.DONE) {
            callback()
        }
    }
    xhr.open('HEAD', src)
}
TC5550

Ähnliche Antworten wie “Knoten, wenn die Datei vorliegt”

Fragen ähnlich wie “Knoten, wenn die Datei vorliegt”

Weitere verwandte Antworten zu “Knoten, wenn die Datei vorliegt” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen