Modul import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });4 memungkinkan interaksi dengan sistem file dengan cara yang dimodelkan pada fungsi POSIX standar
Untuk menggunakan API berbasis janji
import * as fs from 'node:fs/promises';const fs = require('node:fs/promises');_Untuk menggunakan API panggilan balik dan sinkronisasi
import * as fs from 'node:fs';const fs = require('node:fs');Semua operasi sistem file memiliki bentuk sinkron, panggilan balik, dan berbasis janji, dan dapat diakses menggunakan sintaks CommonJS dan Modul ES6 (ESM)
Contoh janji
Operasi berbasis janji mengembalikan janji yang dipenuhi saat operasi asinkron selesai
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');Contoh panggilan balik
Formulir callback menggunakan fungsi callback penyelesaian sebagai argumen terakhirnya dan memanggil operasi secara asinkron. Argumen yang diteruskan ke callback penyelesaian bergantung pada metode, tetapi argumen pertama selalu dicadangkan untuk pengecualian. Jika operasi berhasil diselesaikan, maka argumen pertama adalah import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_Versi berbasis callback dari API modul import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });4 lebih disukai daripada penggunaan API janji ketika kinerja maksimal (baik dalam hal waktu eksekusi dan alokasi memori) diperlukan
Contoh sinkron
API sinkron memblokir Node. js event loop dan selanjutnya eksekusi JavaScript hingga operasi selesai. Pengecualian dilemparkan segera dan dapat ditangani menggunakan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });8, atau dapat dibiarkan meluap
Janji API
HistoryVersionChangesv14. 0. 0
Diekspos sebagai import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_9
v11. 14. 0, v10. 17. 0API ini tidak lagi eksperimental
v10. 1. 0API hanya dapat diakses melalui import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();0
v10. 0. 0Ditambahkan. v10. 0. 0
API import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_1 menyediakan metode sistem file asinkron yang mengembalikan promise
API janji menggunakan Node yang mendasarinya. js threadpool untuk melakukan operasi sistem file dari utas loop acara. These operations are not synchronized or threadsafe. Care must be taken when performing multiple concurrent modifications on the same file or data corruption may occur
Class. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();2
A object is an object wrapper for a numeric file descriptor
Instances of the object are created by the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();3 method
Semua objek adalah s
If a is not closed using the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();4 method, it will try to automatically close the file descriptor and emit a process warning, helping to prevent memory leaks. Please do not rely on this behavior because it can be unreliable and the file may not be closed. Instead, always explicitly close s. Node. js may change this behavior in the future
Event. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5 event is emitted when the has been closed and can no longer be used
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();7HistoryVersionChangesv15. 14. 0, v14. 18. 0
The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 argument supports import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();9, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();0, and import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();1
v14. 0. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter won't coerce unsupported input to strings anymore
v10. 0. 0Ditambahkan. v10. 0. 0
Alias of
When operating on file handles, the mode cannot be changed from what it was set to with . Therefore, this is equivalent to
import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();6Modifies the permissions on the file. See import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();7
import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();8- import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();9 The file's new owner's user id
- import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }0 The file's new group's group id
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
Changes the ownership of the file. A wrapper for import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }2
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();4- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
Closes the file handle after waiting for any pending operation on the handle to complete
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }5Unlike the 16 KiB default import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }6 for a , the stream returned by this method has a default import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }6 of 64 KiB
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 can include import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 and import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }0 values to read a range of bytes from the file instead of the entire file. Both import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 and import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }0 are inclusive and start counting at 0, allowed values are in the [0, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }3] range. If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 is omitted or import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }6 reads sequentially from the current file position. The import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 can be any one of those accepted by
If the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();2 points to a character device that only supports blocking reads (such as keyboard or sound card), read operations do not finish until data is available. This can prevent the process from exiting and the stream from closing naturally
By default, the stream will emit a import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5 event after it has been destroyed. Set the import * as fs from 'node:fs';const fs = require('node:fs');00 option to import * as fs from 'node:fs';const fs = require('node:fs');01 to change this behavior
If import * as fs from 'node:fs';const fs = require('node:fs');02 is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak. If import * as fs from 'node:fs';const fs = require('node:fs');02 is set to true (default behavior), on import * as fs from 'node:fs';const fs = require('node:fs');04 or import * as fs from 'node:fs';const fs = require('node:fs');05 the file descriptor will be closed automatically
An example to read the last 10 bytes of a file which is 100 bytes long
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });import * as fs from 'node:fs';const fs = require('node:fs');06import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 may also include a import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 option to allow writing data at some position past the beginning of the file, allowed values are in the [0, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }3] range. Modifying a file rather than replacing it may require the import * as fs from 'node:fs';const fs = require('node:fs');10 import * as fs from 'node:fs';const fs = require('node:fs');11 option to be set to import * as fs from 'node:fs';const fs = require('node:fs');12 rather than the default import * as fs from 'node:fs';const fs = require('node:fs');13. The import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 can be any one of those accepted by
If import * as fs from 'node:fs';const fs = require('node:fs');02 is set to true (default behavior) on import * as fs from 'node:fs';const fs = require('node:fs');04 or import * as fs from 'node:fs';const fs = require('node:fs');17 the file descriptor will be closed automatically. If import * as fs from 'node:fs';const fs = require('node:fs');02 is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak
By default, the stream will emit a import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5 event after it has been destroyed. Set the import * as fs from 'node:fs';const fs = require('node:fs');00 option to import * as fs from 'node:fs';const fs = require('node:fs');01 to change this behavior
import * as fs from 'node:fs';const fs = require('node:fs');22- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');24 documentation for details
Unlike import * as fs from 'node:fs';const fs = require('node:fs');25 this method does not flush modified metadata
import * as fs from 'node:fs';const fs = require('node:fs');26import * as fs from 'node:fs';const fs = require('node:fs');27- import * as fs from 'node:fs';const fs = require('node:fs');28 . . A buffer that will be filled with the file data read
- import * as fs from 'node:fs';const fs = require('node:fs');29 The location in the buffer at which to start filling
- import * as fs from 'node:fs';const fs = require('node:fs');30 The number of bytes to read
- import * as fs from 'node:fs';const fs = require('node:fs');31 . The location where to begin reading data from the file. If import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5, data will be read from the current file position, and the position will be updated. Jika import * as fs from 'node:fs';const fs = require('node:fs');31 adalah bilangan bulat, posisi file saat ini tidak akan berubah
- Returns. Fulfills upon success with an object with two properties
Reads data from the file and stores that in the given buffer
If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero
import * as fs from 'node:fs';const fs = require('node:fs');34Added in. v13. 11. 0, v12. 17. 0
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import * as fs from 'node:fs';const fs = require('node:fs');28 . . Buffer yang akan diisi dengan data file yang dibaca. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_37
- import * as fs from 'node:fs';const fs = require('node:fs');29 Lokasi di buffer untuk mulai mengisi. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import * as fs from 'node:fs';const fs = require('node:fs');30 Jumlah byte yang akan dibaca. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_41
- import * as fs from 'node:fs';const fs = require('node:fs');_31. Lokasi untuk mulai membaca data dari file. Jika import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5, data akan dibaca dari posisi file saat ini, dan posisi akan diperbarui. Jika import * as fs from 'node:fs';const fs = require('node:fs');31 adalah bilangan bulat, posisi file saat ini tidak akan berubah. Bawaan. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
- Returns. Fulfills upon success with an object with two properties
- import * as fs from 'node:fs';const fs = require('node:fs');28 . . A buffer that will be filled with the file data read
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import * as fs from 'node:fs';const fs = require('node:fs');29 Lokasi di buffer untuk mulai mengisi. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import * as fs from 'node:fs';const fs = require('node:fs');30 Jumlah byte yang akan dibaca. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_41
- import * as fs from 'node:fs';const fs = require('node:fs');31 Lokasi dimana mulai membaca data dari file. Jika import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5, data akan dibaca dari posisi file saat ini, dan posisi akan diperbarui. Jika import * as fs from 'node:fs';const fs = require('node:fs');31 adalah bilangan bulat, posisi file saat ini tidak akan berubah. Bawaan. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
- Returns. Fulfills upon success with an object with two properties
- import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 .
- Returns. Fulfills upon a successful read with the contents of the file. Jika tidak ada penyandian yang ditentukan (menggunakan import * as fs from 'node:fs';const fs = require('node:fs');65), data dikembalikan sebagai objek. Jika tidak, data akan berupa string
- import * as fs from 'node:fs';const fs = require('node:fs');74 . .
- import * as fs from 'node:fs';const fs = require('node:fs');31 . The offset from the beginning of the file where the data should be read from. If import * as fs from 'node:fs';const fs = require('node:fs');31 is not a import * as fs from 'node:fs';const fs = require('node:fs');77, the data will be read from the current position. Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
- Returns. Memenuhi keberhasilan objek yang berisi dua properti
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
- import * as fs from 'node:fs';const fs = require('node:fs');28 . .
- import * as fs from 'node:fs';const fs = require('node:fs');29 The start position from within import * as fs from 'node:fs';const fs = require('node:fs');28 where the data to write begins
- import * as fs from 'node:fs';const fs = require('node:fs');30 The number of bytes from import * as fs from 'node:fs';const fs = require('node:fs');28 to write. Default. import * as fs from 'node:fs';const fs = require('node:fs');41
- import * as fs from 'node:fs';const fs = require('node:fs');31 . The offset from the beginning of the file where the data from import * as fs from 'node:fs';const fs = require('node:fs');28 should be written. If import * as fs from 'node:fs';const fs = require('node:fs');31 is not a import * as fs from 'node:fs';const fs = require('node:fs');77, the data will be written at the current position. See the POSIX import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');04 documentation for more detail. Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
- Returns.
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15
- import * as fs from 'node:fs';const fs = require('node:fs');31 . The offset from the beginning of the file where the data from import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 should be written. If import * as fs from 'node:fs';const fs = require('node:fs');31 is not a import * as fs from 'node:fs';const fs = require('node:fs');77 the data will be written at the current position. See the POSIX import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');04 documentation for more detail. Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
- import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 The expected string encoding. Default. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');24
- Returns.
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27 the number of bytes written
- import * as fs from 'node:fs';const fs = require('node:fs');28 a reference to the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 written
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 . . source filename to copy
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 . . destination filename of the copy operation
- import { unlink } from 'node:fs/promises';
try {
await unlink('/tmp/hello');
console.log('successfully deleted /tmp/hello');
} catch (error) {
console.error('there was an error:', error.message);
}const { unlink } = require('node:fs/promises');
(async function(path) {
try {
await unlink(path);
console.log(`successfully deleted ${path}`);
} catch (error) {
console.error('there was an error:', error.message);
}
})('/tmp/hello');48 Optional modifiers that specify the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e. g. import { unlink } from 'node:fs/promises';
try {
await unlink('/tmp/hello');
console.log('successfully deleted /tmp/hello');
} catch (error) {
console.error('there was an error:', error.message);
}const { unlink } = require('node:fs/promises');
(async function(path) {
try {
await unlink(path);
console.log(`successfully deleted ${path}`);
} catch (error) {
console.error('there was an error:', error.message);
}
})('/tmp/hello');75) Default. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_77. The copy operation will fail if import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 already exists
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');79. Operasi penyalinan akan mencoba membuat tautan ref copy-on-write. Jika platform tidak mendukung copy-on-write, maka mekanisme copy fallback akan digunakan
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');80. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_72. jalur sumber untuk disalin
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_73. jalur tujuan untuk disalin
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');90 symlink dereferensi. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 adalah import * as fs from 'node:fs';const fs = require('node:fs');01, dan tujuan ada, melemparkan kesalahan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');96 Berfungsi untuk memfilter file/direktori yang disalin. Kembalikan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97 untuk menyalin item, import * as fs from 'node:fs';const fs = require('node:fs');01 untuk mengabaikannya. Can also return a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');99 that resolves to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 or import * as fs from 'node:fs';const fs = require('node:fs');01 Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_6
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 menimpa file atau direktori yang ada. Operasi penyalinan akan mengabaikan kesalahan jika Anda menyetelnya ke false dan tujuan ada. Use the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 option to change this behavior. Bawaan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_06 Kapan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 cap waktu dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 akan dipertahankan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 menyalin direktori secara rekursif Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');86 Saat import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, resolusi jalur untuk symlink akan dilewati. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, lakukan penghapusan direktori secara rekursif. Dalam mode rekursif, operasi dicoba kembali jika gagal. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01. Tidak digunakan lagi
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 Ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, pengecualian akan diabaikan jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 tidak ada. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js akan mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, lakukan penghapusan direktori secara rekursif. Dalam mode rekursif, operasi dicoba kembali jika gagal. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
- Returns. Fulfills with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 upon success
- Nilai dapat berupa angka yang mewakili waktu zaman Unix, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });05s, atau string numerik seperti import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });06
- Jika nilainya tidak dapat dikonversi menjadi angka, atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08, atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });09, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });10 akan dilemparkan
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_12. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8 .
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });14 Indicates whether the process should continue to run as long as files are being watched. Bawaan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Menunjukkan apakah semua subdirektori harus diawasi, atau hanya direktori saat ini. Ini berlaku ketika direktori ditentukan, dan hanya pada platform yang didukung (Lihat ). Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');01
- import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 Menentukan pengkodean karakter yang akan digunakan untuk nama file yang diteruskan ke pendengar. Default. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_24
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });20 Digunakan untuk memberi isyarat kapan pengamat harus berhenti
- Pengembalian. objek dengan sifat-sifatnya
- Pemilik dapat membaca, menulis, dan mengeksekusi file
- Grup dapat membaca dan menulis file
- Orang lain dapat membaca dan mengeksekusi file
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_77. The copy operation will fail if import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 already exists
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');79. Operasi penyalinan akan mencoba membuat tautan ref copy-on-write. Jika platform tidak mendukung copy-on-write, maka mekanisme copy fallback akan digunakan
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');80. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_72. jalur sumber untuk disalin
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_73. jalur tujuan untuk disalin
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');90 symlink dereferensi. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 adalah import * as fs from 'node:fs';const fs = require('node:fs');01, dan tujuan ada, melemparkan kesalahan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');96 Berfungsi untuk memfilter file/direktori yang disalin. Kembalikan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97 untuk menyalin item, import * as fs from 'node:fs';const fs = require('node:fs');01 untuk mengabaikannya. Can also return a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');99 that resolves to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 or import * as fs from 'node:fs';const fs = require('node:fs');01 Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_6
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 menimpa file atau direktori yang ada. Operasi penyalinan akan mengabaikan kesalahan jika Anda menyetelnya ke false dan tujuan ada. Use the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 option to change this behavior. Bawaan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_06 Kapan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 cap waktu dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 akan dipertahankan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 menyalin direktori secara rekursif Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');86 Saat import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, resolusi jalur untuk symlink akan dilewati. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49
- import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64
- import * as fs from 'node:fs';const fs = require('node:fs');28 . . The buffer that the data will be written to
- import * as fs from 'node:fs';const fs = require('node:fs');29 The position in import * as fs from 'node:fs';const fs = require('node:fs');28 to write the data to
- import * as fs from 'node:fs';const fs = require('node:fs');30 The number of bytes to read
- import * as fs from 'node:fs';const fs = require('node:fs');31 . . Specifies where to begin reading from in the file. If import * as fs from 'node:fs';const fs = require('node:fs');31 is import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 or import * as fs from 'node:fs';const fs = require('node:fs');070, data will be read from the current file position, and the file position will be updated. If import * as fs from 'node:fs';const fs = require('node:fs');31 is an integer, the file position will be unchanged
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49
- Any specified file descriptor has to support reading
- If a file descriptor is specified as the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47, it will not be closed automatically
- The reading will begin at the current position. For example, if the file already had import * as fs from 'node:fs';const fs = require('node:fs');137' and six bytes are read with the file descriptor, the call to import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75 with the same file descriptor, would give import * as fs from 'node:fs';const fs = require('node:fs');139, rather than import * as fs from 'node:fs';const fs = require('node:fs');140
No case conversion is performed on case-insensitive file systems
The maximum number of symbolic links is platform-independent and generally (much) higher than what the native import * as fs from 'node:fs';const fs = require('node:fs');192 implementation supports
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, lakukan penghapusan direktori secara rekursif. Dalam mode rekursif, operasi dicoba kembali jika gagal. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01. Tidak digunakan lagi
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 Ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, pengecualian akan diabaikan jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 tidak ada. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js akan mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, perform a recursive removal. In recursive mode operations are retried on failure. Default. import * as fs from 'node:fs';const fs = require('node:fs');01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49
- Values can be either numbers representing Unix epoch time in seconds, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });05s, or a numeric string like import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });06
- Jika nilainya tidak dapat dikonversi menjadi angka, atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08, atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });09, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });10 akan dilemparkan
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_12. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8 .
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });14 Indicates whether the process should continue to run as long as files are being watched. Bawaan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Menunjukkan apakah semua subdirektori harus diawasi, atau hanya direktori saat ini. Ini berlaku ketika direktori ditentukan, dan hanya pada platform yang didukung (Lihat ). Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');01
- import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 Menentukan pengkodean karakter yang akan digunakan untuk nama file yang diteruskan ke pendengar. Default. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_24
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });20 allows closing the watcher with an AbortSignal
- import * as fs from 'node:fs';const fs = require('node:fs');389 . Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
- Returns.
- On Linux systems, this uses import * as fs from 'node:fs';const fs = require('node:fs');455
- On BSD systems, this uses import * as fs from 'node:fs';const fs = require('node:fs');456
- On macOS, this uses import * as fs from 'node:fs';const fs = require('node:fs');456 for files and import * as fs from 'node:fs';const fs = require('node:fs');458 for directories
- On SunOS systems (including Solaris and SmartOS), this uses import * as fs from 'node:fs';const fs = require('node:fs');459
- On Windows systems, this feature depends on import * as fs from 'node:fs';const fs = require('node:fs');460
- On AIX systems, this feature depends on import * as fs from 'node:fs';const fs = require('node:fs');461, which must be enabled
- On IBM i systems, this feature is not supported
- the file is deleted, followed by a restore
- the file is renamed and then renamed a second time back to its original name
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_77. The copy operation will fail if import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 already exists
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');79. Operasi penyalinan akan mencoba membuat tautan ref copy-on-write. Jika platform tidak mendukung copy-on-write, maka mekanisme copy fallback akan digunakan
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');80. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_72. jalur sumber untuk disalin
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_73. jalur tujuan untuk disalin
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');90 symlink dereferensi. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 adalah import * as fs from 'node:fs';const fs = require('node:fs');01, dan tujuan ada, melemparkan kesalahan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');96 Function to filter copied files/directories. Return import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 to copy the item, import * as fs from 'node:fs';const fs = require('node:fs');01 to ignore it. Default. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 menimpa file atau direktori yang ada. Operasi penyalinan akan mengabaikan kesalahan jika Anda menyetelnya ke false dan tujuan ada. Use the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');92 option to change this behavior. Bawaan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_97
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_06 Kapan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 cap waktu dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 akan dipertahankan. Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 menyalin direktori secara rekursif Default. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');86 Saat import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, resolusi jalur untuk symlink akan dilewati. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
Synchronously copies the entire directory structure from import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73, including subdirectories and files
When copying a directory to another directory, globs are not supported and behavior is similar to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });18
import * as fs from 'node:fs';const fs = require('node:fs');_719
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the path exists, import * as fs from 'node:fs';const fs = require('node:fs');01 otherwise
For detailed information, see the documentation of the asynchronous version of this API.
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }47 is deprecated, but import * as fs from 'node:fs';const fs = require('node:fs');727 is not. The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 parameter to import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }47 accepts parameters that are inconsistent with other Node. js callbacks. import * as fs from 'node:fs';const fs = require('node:fs');727 does not use a callback
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }6import * as fs from 'node:fs';const fs = require('node:fs');731
Sets the permissions on the file. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }61 documentation for more detail
import * as fs from 'node:fs';const fs = require('node:fs');734
Sets the owner of the file. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }69 documentation for more detail
import * as fs from 'node:fs';const fs = require('node:fs');737
Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');24 documentation for details. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');740
HistoryVersionChangesv10. 5. 0
Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v0. 1. 95Added in. v0. 1. 95
Retrieves the for the file descriptor
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }86 documentation for more detail
import * as fs from 'node:fs';const fs = require('node:fs');743
Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');83 documentation for more detail. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');746
Truncates the file descriptor. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');749
HistoryVersionChangesv4. 1. 0
Numeric strings, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08 are now allowed time specifiers
v0. 4. 2Added in. v0. 4. 2
Synchronous version of . Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');754
Changes the permissions on a symbolic link. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
Metode ini hanya diterapkan di macOS
See the POSIX import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }27 documentation for more detail
import * as fs from 'node:fs';const fs = require('node:fs');757
HistoryVersionChangesv10. 6. 0
This API is no longer deprecated
v0. 4. 7Documentation-only deprecation
Set the owner for the path. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
See the POSIX import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }35 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');760
Added in. v14. 5. 0, v12. 19. 0
Change the file system timestamps of the symbolic link referenced by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6, or throws an exception when parameters are incorrect or the operation fails. This is the synchronous version of
import * as fs from 'node:fs';const fs = require('node:fs');764
HistoryVersionChangesv7. 6. 0
The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });24 and import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Support is currently still experimental
v0. 1. 31Ditambahkan. v0. 1. 31
Creates a new link from the import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });24 to the import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25. See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });26 documentation for more detail. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');773
HistoryVersionChangesv15. 3. 0, v14. 17. 0
Accepts a import * as fs from 'node:fs';const fs = require('node:fs');774 option to specify whether an exception should be thrown if the entry does not exist
v10. 5. 0Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 30Ditambahkan. v0. 1. 30
Mengambil untuk tautan simbolis yang dirujuk oleh import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47
See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });31 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');781
HistoryVersionChangesv13. 11. 0, v12. 17. 0
In import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 mode, the first created path is returned now
v10. 12. 0The second argument can now be an import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object with import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 properties
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Synchronously creates a directory. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6, or if import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the first directory path created. This is the synchronous version of
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');001 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');794
HistoryVersionChangesv16. 5. 0, v14. 18. 0
Parameter import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 sekarang menerima string kosong
v5. 10. 0Ditambahkan. v5. 10. 0
Returns the created directory path
For detailed information, see the documentation of the asynchronous version of this API.
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use
import * as fs from 'node:fs';const fs = require('node:fs');799
HistoryVersionChangesv13. 1. 0, v12. 16. 0
Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });61 diperkenalkan
v12. 12. 0Added in. v12. 12. 0
Synchronously open a directory. See import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });62
Membuat , yang berisi semua fungsi lebih lanjut untuk membaca dari dan membersihkan direktori
Opsi import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 menetapkan pengkodean untuk import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 saat membuka direktori dan operasi baca selanjutnya
import * as fs from 'node:fs';const fs = require('node:fs');804
HistoryVersionChangesv11. 1. 0
Argumen import * as fs from 'node:fs';const fs = require('node:fs');_10 sekarang opsional dan default ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });57
v9. 9. 0The import * as fs from 'node:fs';const fs = require('node:fs');030 and import * as fs from 'node:fs';const fs = require('node:fs');031 flags are supported now
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Returns an integer representing the file descriptor
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');813
HistoryVersionChangesv10. 10. 0
Opsi baru import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_66 telah ditambahkan
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Reads the contents of the directory
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');103 documentation for more details
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the filenames returned. Jika import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 disetel ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, nama file yang dikembalikan akan diteruskan sebagai objek
If import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });71 is set to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the result will contain objects
import * as fs from 'node:fs';const fs = require('node:fs');825
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v5. 0. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameter can be a file descriptor now
v0. 1. 8Added in. v0. 1. 8
Returns the contents of the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47
For detailed information, see the documentation of the asynchronous version of this API.
If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 option is specified then this function returns a string. Otherwise it returns a buffer
Similar to , when the path is a directory, the behavior of import * as fs from 'node:fs';const fs = require('node:fs');130 is platform-specific
import * as fs from 'node:fs';const fs = require('node:fs');835
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 31Ditambahkan. v0. 1. 31
Mengembalikan nilai string tautan simbolik
See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });84 documentation for more details
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the link path returned. Jika import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 disetel ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, jalur tautan yang dikembalikan akan diteruskan sebagai objek
import * as fs from 'node:fs';const fs = require('node:fs');844
HistoryVersionChangesv10. 10. 0
The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056 or a import * as fs from 'node:fs';const fs = require('node:fs');057
v6. 0. 0The import * as fs from 'node:fs';const fs = require('node:fs');30 parameter can now be import * as fs from 'node:fs';const fs = require('node:fs');39
v0. 1. 21Added in. v0. 1. 21
Returns the number of import * as fs from 'node:fs';const fs = require('node:fs');077
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');852
HistoryVersionChangesv13. 13. 0, v12. 17. 0
Options object can be passed in to make offset, length, and position optional
v13. 13. 0, v12. 17. 0Added in. v13. 13. 0, v12. 17. 0
Returns the number of import * as fs from 'node:fs';const fs = require('node:fs');077
Similar to the above import * as fs from 'node:fs';const fs = require('node:fs');854 function, this version takes an optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object. If no import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object is specified, it will default with the above values
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');858
Added in. v13. 13. 0, v12. 17. 0
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');860
HistoryVersionChangesv8. 0. 0
Pipe/Socket resolve support was added
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v6. 4. 0Calling import * as fs from 'node:fs';const fs = require('node:fs');864 now works again for various edge cases on Windows
v6. 0. 0Parameter import * as fs from 'node:fs';const fs = require('node:fs');_189 telah dihapus
v0. 1. 31Ditambahkan. v0. 1. 31
Returns the resolved pathname
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');867
Synchronous import * as fs from 'node:fs';const fs = require('node:fs');192
Hanya jalur yang dapat dikonversi ke string UTF8 yang didukung
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the path returned. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the path returned will be passed as a object
On Linux, when Node. js ditautkan dengan musl libc, sistem file procfs harus dipasang pada import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });97 agar fungsi ini berfungsi. Glibc tidak memiliki batasan ini
import * as fs from 'node:fs';const fs = require('node:fs');874
HistoryVersionChangesv7. 6. 0
The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });99 and import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Support is currently still experimental
v0. 1. 21Added in. v0. 1. 21
Renames the file from import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });99 to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');229 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');883
HistoryVersionChangesv16. 0. 0
Using import * as fs from 'node:fs';const fs = require('node:fs');884 on a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 that is a file is no longer permitted and results in an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error on Windows and an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 error on POSIX
v16. 0. 0Using import * as fs from 'node:fs';const fs = require('node:fs');884 on a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 that does not exist is no longer permitted and results in a import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error
v16. 0. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 sudah tidak digunakan lagi, menggunakannya akan memicu peringatan penghentian
v14. 14. 0The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 option is deprecated, use import * as fs from 'node:fs';const fs = require('node:fs');893 instead
v13. 3. 0, v12. 16. 0Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_12 diganti namanya menjadi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }13, dan standarnya adalah 0. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_14 telah dihapus, dan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15 menggunakan logika coba lagi yang sama seperti kesalahan lainnya. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 sekarang didukung. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_17 kesalahan sekarang dicoba lagi
v12. 10. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }12, dan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }14 sekarang didukung
v7. 6. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameters can be a WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 object using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol
v0. 1. 21Added in. v0. 1. 21
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, lakukan penghapusan direktori secara rekursif. Dalam mode rekursif, operasi dicoba kembali jika gagal. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01. Tidak digunakan lagi
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
Synchronous import * as fs from 'node:fs';const fs = require('node:fs');279. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
Using import * as fs from 'node:fs';const fs = require('node:fs');927 on a file (not a directory) results in an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error on Windows and an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 error on POSIX
To get a behavior similar to the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }45 Unix command, use with options import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }47
import * as fs from 'node:fs';const fs = require('node:fs');933
HistoryVersionChangesv17. 3. 0, v16. 14. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v14. 14. 0Added in. v14. 14. 0
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47. .
- import { open } from 'node:fs/promises';
let filehandle = null;
try {
filehandle = await open('temp.txt', 'r+');
await filehandle.truncate(4);
} finally {
await filehandle?.close();
}8
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');93 Ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, pengecualian akan diabaikan jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 tidak ada. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_13 Jika terjadi kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }24, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }17, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }27, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28, Node. js akan mencoba kembali operasi dengan menunggu mundur linier import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }16 milidetik lebih lama pada setiap percobaan. Opsi ini mewakili jumlah percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_39
- import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, lakukan penghapusan direktori secara rekursif. Dalam mode rekursif, operasi dicoba kembali jika gagal. Bawaan. import * as fs from 'node:fs';const fs = require('node:fs');_01
- import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 Jumlah waktu dalam milidetik untuk menunggu di antara percobaan ulang. Opsi ini diabaikan jika opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_10 bukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97. Bawaan. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_39
Synchronously removes files and directories (modeled on the standard POSIX import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }73 utility). Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');962
HistoryVersionChangesv15. 3. 0, v14. 17. 0
Accepts a import * as fs from 'node:fs';const fs = require('node:fs');774 option to specify whether an exception should be thrown if the entry does not exist
v10. 5. 0Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Retrieves the for the path
import * as fs from 'node:fs';const fs = require('node:fs');968
HistoryVersionChangesv12. 0. 0
If the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 argument is left undefined, Node will autodetect import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 type and automatically select import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }80 or import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }81
v7. 6. 0The import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Dukungan saat ini masih eksperimental
v0. 1. 31Ditambahkan. v0. 1. 31
Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');979
Truncates the file. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6. A file descriptor can also be passed as the first argument. In this case, import * as fs from 'node:fs';const fs = require('node:fs');981 is called
Passing a file descriptor is deprecated and may result in an error being thrown in the future
import * as fs from 'node:fs';const fs = require('node:fs');982
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 21Added in. v0. 1. 21
Synchronous import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });00. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import * as fs from 'node:fs';const fs = require('node:fs');988
HistoryVersionChangesv8. 0. 0
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });09 are no longer valid time specifiers
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v4. 1. 0Numeric strings, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08 are now allowed time specifiers
v0. 4. 2Added in. v0. 4. 2
Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
For detailed information, see the documentation of the asynchronous version of this API.
import * as fs from 'node:fs';const fs = require('node:fs');999
HistoryVersionChangesv19. 0. 0
Passing to the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter an object with an own import * as fs from 'node:fs';const fs = require('node:fs');538 function is no longer supported
v17. 8. 0Passing to the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter an object with an own import * as fs from 'node:fs';const fs = require('node:fs');538 function is deprecated
v14. 12. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter will stringify an object with an explicit import * as fs from 'node:fs';const fs = require('node:fs');538 function
v14. 0. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter won't coerce unsupported input to strings anymore
v10. 10. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056 or a import * as fs from 'node:fs';const fs = require('node:fs');057
v7. 4. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter can now be a import * as fs from 'node:fs';const fs = require('node:fs');059
v5. 0. 0Parameter import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_81 dapat menjadi deskriptor file sekarang
v0. 1. 29Added in. v0. 1. 29
Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
For detailed information, see the documentation of the asynchronous version of this API.
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');017
HistoryVersionChangesv14. 0. 0
The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter won't coerce unsupported input to strings anymore
v10. 10. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056 or a import * as fs from 'node:fs';const fs = require('node:fs');057
v7. 4. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be a import * as fs from 'node:fs';const fs = require('node:fs');059
v7. 2. 0The import * as fs from 'node:fs';const fs = require('node:fs');29 and import * as fs from 'node:fs';const fs = require('node:fs');30 parameters are optional now
v0. 1. 21Added in. v0. 1. 21
For detailed information, see the documentation of the asynchronous version of this API.
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');027
Added in. v18. 3. 0, v16. 17. 0
For detailed information, see the documentation of the asynchronous version of this API.
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');029
HistoryVersionChangesv14. 0. 0
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter won't coerce unsupported input to strings anymore
v7. 2. 0The import * as fs from 'node:fs';const fs = require('node:fs');31 parameter is optional now
v0. 11. 5Added in. v0. 11. 5
For detailed information, see the documentation of the asynchronous version of this API.
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');033
For detailed information, see the documentation of the asynchronous version of this API.
Common Objects
The common objects are shared by all of the file system API variants (promise, callback, and synchronous)
Class. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');035
A class representing a directory stream
Created by , , or
import * as fs from 'node:fs';const fs = require('node:fs');2Saat menggunakan iterator async, objek akan ditutup secara otomatis setelah iterator keluar
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');039Asynchronously close the directory's underlying resource handle. Subsequent reads will result in errors
A promise is returned that will be resolved after the resource has been closed
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');040HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v12. 12. 0Added in. v12. 12. 0
Asynchronously close the directory's underlying resource handle. Subsequent reads will result in errors
The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 will be called after the resource handle has been closed
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');045Synchronously close the directory's underlying resource handle. Subsequent reads will result in errors
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');046The read-only path of this directory as was provided to , , or
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');050Asynchronously read the next directory entry via import * as fs from 'node:fs';const fs = require('node:fs');103 as an
A promise is returned that will be resolved with an , or import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 if there are no more directory entries to read
Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms. Entries added or removed while iterating over the directory might not be included in the iteration results
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');053Asynchronously read the next directory entry via import * as fs from 'node:fs';const fs = require('node:fs');103 as an
After the read is completed, the import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 will be called with an , or import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 if there are no more directory entries to read
Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms. Entries added or removed while iterating over the directory might not be included in the iteration results
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_057Synchronously read the next directory entry as an . See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');103 documentation for more detail
If there are no more directory entries to read, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 will be returned
Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms. Entries added or removed while iterating over the directory might not be included in the iteration results
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');060Asynchronously iterates over the directory until all entries have been read. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');103 documentation for more detail
Entries returned by the async iterator are always an . The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 case from import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');050 is handled internally
See for an example
Directory entries returned by this iterator are in no particular order as provided by the operating system's underlying directory mechanisms. Entries added or removed while iterating over the directory might not be included in the iteration results
Class. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');064
A representation of a directory entry, which can be a file or a subdirectory within the directory, as returned by reading from an . The directory entry is a combination of the file name and file type pairs
Additionally, when or is called with the import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });66 option set to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the resulting array is filled with objects, rather than strings or s
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');069Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a block device
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');071Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a character device
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');073Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a file system directory
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');075Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a first-in-first-out (FIFO) pipe
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');077Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a regular file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');079Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a socket
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');081Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a symbolic link
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');083The file name that this object refers to. The type of this value is determined by the import * as fs from 'node:fs';const fs = require('node:fs');65 passed to or
Class. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');087
A successful call to method will return a new object
All objects emit a import * as fs from 'node:fs';const fs = require('node:fs');446 event whenever a specific watched file is modified
Event. import * as fs from 'node:fs';const fs = require('node:fs');446- import * as fs from 'node:fs';const fs = require('node:fs');444 The type of change event that has occurred
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 . The filename that changed (if relevant/available)
Emitted when something changes in a watched directory or file. See more details in
The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 argument may not be provided depending on operating system support. If import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 is provided, it will be provided as a if import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });24 is called with its import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 option set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, otherwise import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 will be a UTF-8 string
Event. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5Emitted when the watcher stops watching for changes. The closed object is no longer usable in the event handler
Event. import * as fs from 'node:fs';const fs = require('node:fs');04Emitted when an error occurs while watching the file. The errored object is no longer usable in the event handler
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');102Stop watching for changes on the given . Once stopped, the object is no longer usable
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103Added in. v14. 3. 0, v12. 20. 0
When called, requests that the Node. js event loop tidak keluar selama masih aktif. Calling import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103 multiple times will have no effect
Secara default, semua objek "ref'ed", membuatnya biasanya tidak perlu memanggil import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103 kecuali import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');106 telah dipanggil sebelumnya
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_106Added in. v14. 3. 0, v12. 20. 0
Saat dipanggil, objek aktif tidak memerlukan Node. js event loop agar tetap aktif. Jika tidak ada aktivitas lain yang membuat perulangan peristiwa tetap berjalan, proses dapat keluar sebelum panggilan balik objek dipanggil. Memanggil import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_106 beberapa kali tidak akan berpengaruh
Kelas. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');109
Added in. v14. 3. 0, v12. 20. 0
Panggilan yang berhasil ke metode import * as fs from 'node:fs';const fs = require('node:fs');_393 akan mengembalikan objek baru
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103Added in. v14. 3. 0, v12. 20. 0
When called, requests that the Node. js event loop tidak keluar selama masih aktif. Calling import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103 multiple times will have no effect
Secara default, semua objek "ref'ed", membuatnya biasanya tidak perlu memanggil import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');103 kecuali import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');106 telah dipanggil sebelumnya
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_106Added in. v14. 3. 0, v12. 20. 0
Saat dipanggil, objek aktif tidak memerlukan Node. js event loop agar tetap aktif. Jika tidak ada aktivitas lain yang membuat perulangan peristiwa tetap berjalan, proses dapat keluar sebelum panggilan balik objek dipanggil. Memanggil import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_106 beberapa kali tidak akan berpengaruh
Class. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');117
Instances of are created and returned using the function
Event. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5Emitted when the 's underlying file descriptor has been closed
Event. import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();56Emitted when the 's file descriptor has been opened
Event. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');121Emitted when the is ready to be used
Fires immediately after import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();56
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');123The number of bytes that have been read so far
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');124The path to the file the stream is reading from as specified in the first argument to import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();51. If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 is passed as a string, then import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');124 will be a string. If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 is passed as a , then import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');124 will be a . If import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 is specified, then import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');124 will be import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');133Added in. v11. 2. 0, v10. 16. 0
This property is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the underlying file has not been opened yet, i. e. before the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');121 event is emitted
Class. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');136
HistoryVersionChangesv8. 1. 0
Added times as numbers
v0. 1. 21Added in. v0. 1. 21
A object provides information about a file
Objects returned from , , , and their synchronous counterparts are of this type. If import * as fs from 'node:fs';const fs = require('node:fs');470 in the import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 passed to those methods is true, the numeric values will be import * as fs from 'node:fs';const fs = require('node:fs');470 instead of import * as fs from 'node:fs';const fs = require('node:fs');77, and the object will contain additional nanosecond-precision properties suffixed with import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');144
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }8import * as fs from 'node:fs';const fs = require('node:fs');470 version
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }9import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');146Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a block device
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');148Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a character device
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');150Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a file system directory
If the object was obtained from , this method will always return import * as fs from 'node:fs';const fs = require('node:fs');01. This is because returns information about a symbolic link itself and not the path it resolves to
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');155Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a first-in-first-out (FIFO) pipe
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');157Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a regular file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');159Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a socket
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');161Returns import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the object describes a symbolic link
This method is only valid when using
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');164The numeric identifier of the device containing the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');165The file system specific "Inode" number for the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');166A bit-field describing the file type and mode
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');167The number of hard-links that exist for the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');168The numeric user identifier of the user that owns the file (POSIX)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');169The numeric group identifier of the group that owns the file (POSIX)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');170A numeric device identifier if the file represents a device
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');171The size of the file in bytes
If the underlying file system does not support getting the size of the file, this will be import * as fs from 'node:fs';const fs = require('node:fs');39
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');173Ukuran blok sistem file untuk operasi i/o
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_174Jumlah blok yang dialokasikan untuk file ini
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_175Stempel waktu yang menunjukkan kapan terakhir kali file ini diakses dinyatakan dalam milidetik sejak POSIX Epoch
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_176Stempel waktu yang menunjukkan kapan terakhir kali file ini diubah dinyatakan dalam milidetik sejak Zaman POSIX
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');177Stempel waktu yang menunjukkan terakhir kali status file diubah dinyatakan dalam milidetik sejak Zaman POSIX
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_178Stempel waktu yang menunjukkan waktu pembuatan file ini dinyatakan dalam milidetik sejak Zaman POSIX
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_179Hanya hadir ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_180 diteruskan ke metode yang menghasilkan objek. The timestamp indicating the last time this file was accessed expressed in nanoseconds since the POSIX Epoch
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_181Hanya hadir ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_180 diteruskan ke metode yang menghasilkan objek. Stempel waktu yang menunjukkan kapan terakhir kali file ini dimodifikasi dinyatakan dalam nanodetik sejak POSIX Epoch
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_183Hanya hadir ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_180 diteruskan ke metode yang menghasilkan objek. Stempel waktu yang menunjukkan terakhir kali status file diubah dinyatakan dalam nanodetik sejak Zaman POSIX
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_185Hanya hadir ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_180 diteruskan ke metode yang menghasilkan objek. Stempel waktu yang menunjukkan waktu pembuatan file ini dinyatakan dalam nanodetik sejak Zaman POSIX
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_187Stempel waktu yang menunjukkan kapan terakhir kali file ini diakses
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_188Stempel waktu yang menunjukkan kapan terakhir kali file ini diubah
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_189Stempel waktu yang menunjukkan kapan terakhir kali status file diubah
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_190Stempel waktu yang menunjukkan waktu pembuatan file ini
Stat time valuesProperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_191, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');192, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');193, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');194 adalah nilai numerik yang menyimpan waktu yang sesuai dalam milidetik. Ketepatannya spesifik untuk platform. Ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_180 diteruskan ke metode yang menghasilkan objek, propertinya akan menjadi bigints, jika tidak maka akan menjadi
Properti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_196, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');197, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');198, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');199 adalah bigint yang memiliki waktu yang sesuai dalam nanodetik. Mereka hanya hadir ketika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');180 diteruskan ke metode yang menghasilkan objek. Ketepatannya spesifik untuk platform
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });03, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });04, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');203, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');204 adalah import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });05 representasi alternatif objek dari berbagai waktu. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });05 dan nilai angka tidak terhubung. Menetapkan nilai angka baru, atau mengubah nilai import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });05, tidak akan tercermin dalam representasi alternatif yang sesuai
Waktu dalam objek stat memiliki semantik berikut
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_03 "Waktu Akses". Waktu saat data file terakhir diakses. Diubah oleh panggilan sistem import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');209, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');210, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');211
- import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_04 "Waktu yang Diubah". Waktu saat data file terakhir diubah. Diubah oleh panggilan sistem import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');209, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');210, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');215
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');203 "Ubah Waktu". Time when file status was last changed (inode data modification). Diubah oleh panggilan sistem import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();7, import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }2, import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });26, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');209, import * as fs from 'node:fs';const fs = require('node:fs');229, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });00, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');210, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');211, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_215
- import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');204 "Waktu Lahir". Waktu pembuatan file. Tetapkan sekali saat file dibuat. Pada sistem file di mana waktu lahir tidak tersedia, bidang ini malah dapat menampung import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');203 atau import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');228 (yaitu, cap waktu zaman Unix import * as fs from 'node:fs';const fs = require('node:fs');39). Nilai ini mungkin lebih besar dari import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_03 atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });04 dalam hal ini. Di Darwin dan varian FreeBSD lainnya, setel juga jika import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });03 secara eksplisit disetel ke nilai yang lebih awal dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');204 saat ini menggunakan panggilan sistem import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');210
Sebelum Node. js 0. 12, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_203 mengadakan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');204 pada sistem Windows. Pada 0. 12, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');203 bukan "waktu pembuatan", dan pada sistem Unix, tidak pernah ada
Kelas. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_238
Instances of are created and returned using the function
Event. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5Emitted when the 's underlying file descriptor has been closed
Event. import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();56Dipancarkan saat file dibuka
Event. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');121Emitted when the is ready to be used
Fires immediately after import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();56
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_244Jumlah byte yang ditulis sejauh ini. Does not include data that is still queued for writing
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_245Tutup import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_246. Opsional menerima panggilan balik yang akan dieksekusi setelah import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');246 ditutup
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_248Path ke file tempat aliran ditulis seperti yang ditentukan dalam argumen pertama. Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dilewatkan sebagai string, maka import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');248 akan menjadi string. Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dilewatkan sebagai a, maka import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');248 akan menjadi a
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_254This property is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97 if the underlying file has not been opened yet, i. e. before the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');121 event is emitted
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_47
Mengembalikan objek yang berisi konstanta yang biasa digunakan untuk operasi sistem file
konstanta FSKonstanta berikut diekspor oleh import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_47 dan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });46
Tidak setiap konstanta akan tersedia di setiap sistem operasi; . Untuk aplikasi portabel disarankan untuk memeriksa keberadaannya sebelum digunakan
Untuk menggunakan lebih dari satu konstanta, gunakan operator bitwise OR import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');260
Contoh
Konstanta akses fileKonstanta berikut dimaksudkan untuk digunakan sebagai parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_48 yang diteruskan ke , , dan
ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');265Flag indicating that the file is visible to the calling process. Ini berguna untuk menentukan apakah suatu file ada, tetapi tidak mengatakan apa-apa tentang izin import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');266. Default jika tidak ada mode yang ditentukan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');267Flag yang menunjukkan bahwa file dapat dibaca oleh proses pemanggilan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');268Flag menunjukkan bahwa file dapat ditulis oleh proses pemanggilan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');269Bendera yang menunjukkan bahwa file dapat dieksekusi oleh proses pemanggilan. Ini tidak berpengaruh pada Windows (akan berperilaku seperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');50)Definisi juga tersedia di Windows
Konstanta salinan fileKonstanta berikut dimaksudkan untuk digunakan dengan
ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_272Jika ada, operasi penyalinan akan gagal dengan kesalahan jika jalur tujuan sudah ada. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');273Jika ada, operasi penyalinan akan berupaya membuat tautan ref copy-on-write. Jika platform dasar tidak mendukung copy-on-write, maka mekanisme copy fallback akan digunakan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');274 Jika ada, operasi penyalinan akan berupaya membuat tautan ref copy-on-write. Jika platform dasar tidak mendukung copy-on-write, maka operasi akan gagal dengan kesalahanDefinisi juga tersedia di Windows
Buka file konstantaKonstanta berikut dimaksudkan untuk digunakan dengan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64
ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_276Flag menunjukkan untuk membuka file untuk akses read-only. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');277Bendera yang menunjukkan untuk membuka file untuk akses tulis saja. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');278Flag indicating to open a file for read-write access. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');279Bendera yang menunjukkan untuk membuat file jika belum ada. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');280Flag menunjukkan bahwa membuka file harus gagal jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');279 flag diatur dan file sudah ada. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');282Bendera yang menunjukkan bahwa jika jalur mengidentifikasi perangkat terminal, membuka jalur tidak akan menyebabkan terminal tersebut menjadi terminal pengendali untuk proses (jika proses belum memilikinya). import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');283Bendera yang menunjukkan bahwa jika file ada dan merupakan file biasa, dan file berhasil dibuka untuk akses tulis, panjangnya harus dipotong menjadi nol. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');284 Bendera yang menunjukkan bahwa data akan ditambahkan ke akhir file. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');285Tandai yang menunjukkan bahwa pembukaan harus gagal jika jalurnya bukan direktori. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');286Tandai yang menunjukkan akses membaca ke sistem file tidak lagi menghasilkan pembaruan ke import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });03 informasi yang terkait dengan file. Bendera ini hanya tersedia di sistem operasi Linux. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');288Tandai yang menunjukkan bahwa pembukaan harus gagal jika jalurnya adalah tautan simbolik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');289Tandai yang menunjukkan bahwa file dibuka untuk I/O tersinkronisasi dengan operasi tulis menunggu integritas file. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');290Tandai yang menunjukkan bahwa file dibuka untuk I/O tersinkronisasi dengan operasi tulis menunggu integritas data. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');291Tandai yang menunjukkan untuk membuka tautan simbolik itu sendiri daripada sumber daya yang ditunjuknya. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');292 Saat disetel, upaya akan dilakukan untuk meminimalkan efek caching dari file I/O. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');293Bendera yang menunjukkan untuk membuka file dalam mode non-blocking bila memungkinkan. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');294 Saat disetel, pemetaan file memori digunakan untuk mengakses file. Bendera ini hanya tersedia pada sistem operasi Windows. Di sistem operasi lain, flag ini diabaikanDi Windows, hanya import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');284, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');279, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');280, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');276, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');278, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');283, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');277, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');294 tersedia
Konstanta jenis fileKonstanta berikut dimaksudkan untuk digunakan dengan properti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 objek untuk menentukan jenis file
ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_304Bit mask digunakan untuk mengekstrak kode jenis file. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');305 Konstanta tipe file untuk file biasa. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');306 Konstanta tipe file untuk direktori. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');307 Konstanta tipe file untuk file perangkat berorientasi karakter. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');308 Konstanta tipe file untuk file perangkat berorientasi blok. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');309 Konstanta tipe file untuk FIFO/pipa. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');310 Konstanta jenis file untuk tautan simbolik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');311 Konstanta jenis file untuk soketDi Windows, hanya import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_307, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');306, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');310, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');304, dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');305, tersedia
Konstanta mode fileKonstanta berikut dimaksudkan untuk digunakan dengan properti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 objek untuk menentukan izin akses untuk file
ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_318 Mode file menunjukkan dapat dibaca, ditulis, dan dieksekusi oleh pemilik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');319 Mode file menunjukkan dapat dibaca oleh pemilik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');320 Mode file menunjukkan dapat ditulis oleh pemilik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');321 Mode file menunjukkan dapat dieksekusi oleh pemilik. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');322 Mode file menunjukkan dapat dibaca, ditulis, dan dieksekusi oleh grup. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');323 Mode file menunjukkan dapat dibaca oleh grup. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');324 Mode file menunjukkan dapat ditulis oleh grup. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');325File mode indicating executable by group. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');326 Mode file menunjukkan dapat dibaca, ditulis, dan dieksekusi oleh orang lain. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');327 Mode file menunjukkan dapat dibaca oleh orang lain. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');328 Mode file menunjukkan dapat ditulis oleh orang lain. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');329 Mode file menunjukkan dapat dieksekusi oleh orang lainDi Windows, hanya import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');319 dan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');320 yang tersedia
Catatan
Pengurutan callback dan operasi berbasis janji
Karena dieksekusi secara asinkron oleh kumpulan utas yang mendasarinya, tidak ada pemesanan yang dijamin saat menggunakan metode panggilan balik atau metode berbasis janji
Misalnya, berikut ini rawan kesalahan karena operasi import * as fs from 'node:fs';const fs = require('node:fs');330 mungkin selesai sebelum operasi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');333
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });0Penting untuk mengurutkan operasi dengan benar dengan menunggu hasil dari satu operasi sebelum memanggil yang lain
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_1Atau, saat menggunakan API panggilan balik, pindahkan panggilan import * as fs from 'node:fs';const fs = require('node:fs');330 ke dalam panggilan balik operasi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');333
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_2Jalur file
Sebagian besar operasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 menerima jalur file yang dapat ditentukan dalam bentuk string, a , atau objek menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
Jalur stringJalur string ditafsirkan sebagai urutan karakter UTF-8 yang mengidentifikasi nama file absolut atau relatif. Jalur relatif akan diselesaikan relatif terhadap direktori kerja saat ini sebagaimana ditentukan dengan memanggil import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');338
Example using an absolute path on POSIX
Contoh menggunakan jalur relatif pada POSIX (relatif terhadap import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');338)
Jalur URL fileUntuk sebagian besar fungsi modul import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });4, argumen import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 dapat diteruskan sebagai objek menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_3import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 URL selalu merupakan jalur absolut
Pertimbangan khusus platformDi Windows, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 s dengan nama host dikonversi ke jalur UNC, sementara import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 s dengan huruf drive dikonversi ke jalur absolut lokal. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 s tanpa nama host dan tanpa huruf drive akan menghasilkan kesalahan
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 s dengan huruf drive harus menggunakan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');349 sebagai pemisah tepat setelah huruf drive. Menggunakan pemisah lain akan menghasilkan kesalahan
Di semua platform lain, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 s dengan nama host tidak didukung dan akan mengakibatkan kesalahan
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 yang memiliki karakter garis miring yang disandikan akan menyebabkan kesalahan pada semua platform
Di Windows, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_54 s memiliki garis miring terbalik yang disandikan akan menghasilkan kesalahan
Jalur penyanggaJalur yang ditentukan menggunakan a berguna terutama pada sistem operasi POSIX tertentu yang memperlakukan jalur file sebagai urutan byte buram. Pada sistem seperti itu, dimungkinkan untuk jalur file tunggal berisi sub-urutan yang menggunakan pengkodean banyak karakter. Seperti jalur string, jalur mungkin relatif atau absolut
Example using an absolute path on POSIX
Direktori kerja per-drive di WindowsDi Windows, Node. js follows the concept of per-drive working directory. Perilaku ini dapat diamati saat menggunakan jalur drive tanpa garis miring terbalik. Misalnya import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_353 berpotensi mengembalikan hasil yang berbeda dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_354. Untuk informasi lebih lanjut, lihat
File descriptors
Pada sistem POSIX, untuk setiap proses, kernel memelihara tabel file dan sumber daya yang sedang dibuka. Setiap file yang terbuka diberi pengenal numerik sederhana yang disebut deskriptor file. Pada tingkat sistem, semua operasi sistem file menggunakan deskriptor file ini untuk mengidentifikasi dan melacak setiap file tertentu. Sistem Windows menggunakan mekanisme yang berbeda tetapi serupa secara konseptual untuk melacak sumber daya. Untuk menyederhanakan berbagai hal bagi pengguna, Node. js menghilangkan perbedaan antara sistem operasi dan menetapkan semua file yang terbuka sebagai deskriptor file numerik
Metode import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64 berbasis callback, dan sinkron import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });93 membuka file dan mengalokasikan deskriptor file baru. Setelah dialokasikan, deskriptor file dapat digunakan untuk membaca data dari, menulis data, atau meminta informasi tentang file
Sistem operasi membatasi jumlah deskriptor file yang dapat dibuka pada waktu tertentu sehingga sangat penting untuk menutup deskriptor saat operasi selesai. Kegagalan untuk melakukannya akan mengakibatkan kebocoran memori yang pada akhirnya akan menyebabkan aplikasi mogok
API berbasis janji menggunakan objek sebagai pengganti deskriptor file numerik. Objek ini dikelola dengan lebih baik oleh sistem untuk memastikan bahwa sumber daya tidak bocor. Namun, mereka masih harus ditutup ketika operasi selesai
Penggunaan threadpool
Semua callback dan API sistem file berbasis janji (kecuali import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');357) menggunakan threadpool libuv. This can have surprising and negative performance implications for some applications. Lihat dokumentasi untuk informasi lebih lanjut
Bendera sistem file
Bendera berikut tersedia di mana pun opsi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_359 menggunakan string
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_360. Buka file untuk ditambahkan. File dibuat jika tidak ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_361. Seperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_360 tetapi gagal jika jalurnya ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_363. Buka file untuk membaca dan menambahkan. File dibuat jika tidak ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_364. Seperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_363 tetapi gagal jika jalurnya ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_366. Buka file untuk menambahkan dalam mode sinkron. File dibuat jika tidak ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_367. Buka file untuk membaca dan menambahkan dalam mode sinkron. The file is created if it does not exist
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_57. Buka file untuk dibaca. Pengecualian terjadi jika file tidak ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_369. Buka file untuk membaca dan menulis. Pengecualian terjadi jika file tidak ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_370. Buka file untuk membaca dan menulis dalam mode sinkron. Menginstruksikan sistem operasi untuk mem-bypass cache sistem file lokal
Ini terutama berguna untuk membuka file pada mount NFS karena memungkinkan melewatkan cache lokal yang berpotensi basi. Ini memiliki dampak yang sangat nyata pada kinerja I/O sehingga penggunaan flag ini tidak disarankan kecuali diperlukan
Ini tidak mengubah import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64 atau import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();3 menjadi panggilan pemblokiran sinkron. Jika operasi sinkron diinginkan, sesuatu seperti import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });93 harus digunakan
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_374. Buka file untuk menulis. File dibuat (jika tidak ada) atau dipotong (jika ada)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_375. Seperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_374 tetapi gagal jika jalurnya ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_377. Open file for reading and writing. File dibuat (jika tidak ada) atau dipotong (jika ada)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_378. Seperti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_377 tetapi gagal jika jalurnya ada
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');359 juga bisa berupa angka seperti yang didokumentasikan oleh import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });58; . Di Windows, bendera diterjemahkan ke yang setara jika berlaku, mis. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');277 hingga import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');384, atau import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');385 hingga import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');386, sebagaimana diterima oleh import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');387
Bendera eksklusif import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_388 (import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');280 bendera di import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });58) menyebabkan operasi mengembalikan kesalahan jika jalur sudah ada. Di POSIX, jika jalurnya adalah tautan simbolis, menggunakan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');280 mengembalikan kesalahan meskipun tautannya ke jalur yang tidak ada. Bendera eksklusif mungkin tidak berfungsi dengan sistem file jaringan
Di Linux, penulisan posisi tidak berfungsi saat file dibuka dalam mode penambahan. The kernel ignores the position argument and always appends the data to the end of the file
Memodifikasi file daripada menggantinya mungkin memerlukan opsi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');359 untuk disetel ke import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');369 daripada default import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');374
Perilaku beberapa bendera bersifat khusus platform. Dengan demikian, membuka direktori di macOS dan Linux dengan flag import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');363, seperti pada contoh di bawah, akan menghasilkan error. Sebaliknya, pada Windows dan FreeBSD, deskriptor file atau import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();2 akan dikembalikan
Di Windows, membuka file tersembunyi yang ada menggunakan bendera import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');374 (baik melalui import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76, atau import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();3) akan gagal dengan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28. File tersembunyi yang ada dapat dibuka untuk ditulisi dengan flag import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');369
Node. Untuk apa js digunakan?
Simpul. js adalah platform yang dibuat khusus untuk membantu pengembangan aplikasi berbasis web . Namun, Node. js bukanlah bahasa pemrograman baru, melainkan runtime environment atau interpreter untuk menjalankan bahasa pemrograman JavaScript sebagai kebutuhan back-end development.Bagaimana karakteristik api pada Node. js asinkron?
Semua API dari Node . js adalah asinkron , artinya tidak memblokir proses lain saat menunggu satu proses untuk diselesaikan.
Reads data from the file and stores that in the given buffer
If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero
import * as fs from 'node:fs';const fs = require('node:fs');_46Ditambahkan. v18. 2. 0, v16. 17. 0
Reads data from the file and stores that in the given buffer
If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero
import * as fs from 'node:fs';const fs = require('node:fs');_57Mengembalikan import * as fs from 'node:fs';const fs = require('node:fs');_58 yang dapat digunakan untuk membaca file data
Kesalahan akan dilemparkan jika metode ini dipanggil lebih dari sekali atau dipanggil setelah import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();2 ditutup atau ditutup
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();While the import * as fs from 'node:fs';const fs = require('node:fs');58 will read the file to completion, it will not close the import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();2 automatically. User code must still call the import * as fs from 'node:fs';const fs = require('node:fs');62 method
import * as fs from 'node:fs';const fs = require('node:fs');_63Asynchronously reads the entire contents of a file
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7
Harus mendukung membaca
Jika satu atau lebih import * as fs from 'node:fs';const fs = require('node:fs');_68 panggilan dilakukan pada pegangan file dan kemudian panggilan import * as fs from 'node:fs';const fs = require('node:fs');69 dilakukan, data akan dibaca dari posisi saat ini hingga akhir file. Itu tidak selalu membaca dari awal file
import * as fs from 'node:fs';const fs = require('node:fs');70Metode kenyamanan untuk membuat antarmuka import * as fs from 'node:fs';const fs = require('node:fs');71 dan streaming melalui file. See for the options
import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();import * as fs from 'node:fs';const fs = require('node:fs');73Added in. v13. 13. 0, v12. 17. 0
Read from a file and write to an array of s
import * as fs from 'node:fs';const fs = require('node:fs');79HistoryVersionChangesv10. 5. 0
Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Ditambahkan. v10. 0. 0
import * as fs from 'node:fs';const fs = require('node:fs');81Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');83 documentation for more detail
import * as fs from 'node:fs';const fs = require('node:fs');84Truncates the file
If the file was larger than import * as fs from 'node:fs';const fs = require('node:fs');85 bytes, only the first import * as fs from 'node:fs';const fs = require('node:fs');85 bytes will be retained in the file
The following example retains only the first four bytes of the file
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }If the file previously was shorter than import * as fs from 'node:fs';const fs = require('node:fs');85 bytes, it is extended, and the extended part is filled with null bytes (import * as fs from 'node:fs';const fs = require('node:fs');88)
If import * as fs from 'node:fs';const fs = require('node:fs');85 is negative then import * as fs from 'node:fs';const fs = require('node:fs');39 will be used
import * as fs from 'node:fs';const fs = require('node:fs');91Change the file system timestamps of the object referenced by the then resolves the promise with no arguments upon success
import * as fs from 'node:fs';const fs = require('node:fs');92HistoryVersionChangesv14. 0. 0
The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter won't coerce unsupported input to buffers anymore
v10. 0. 0Ditambahkan. v10. 0. 0
Write import * as fs from 'node:fs';const fs = require('node:fs');28 to the file
The promise is resolved with an object containing two properties
It is unsafe to use import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');07 multiple times on the same file without waiting for the promise to be resolved (or rejected). For this scenario, use
On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');09Added in. v18. 3. 0, v16. 17. 0
Write import * as fs from 'node:fs';const fs = require('node:fs');28 to the file
Similar to the above import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');11 function, this version takes an optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object. If no import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object is specified, it will default with the above values
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');14HistoryVersionChangesv14. 0. 0
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter won't coerce unsupported input to strings anymore
v10. 0. 0Ditambahkan. v10. 0. 0
Write import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 to the file. If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 is not a string, the promise is rejected with an error
The promise is resolved with an object containing two properties
It is unsafe to use import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');07 multiple times on the same file without waiting for the promise to be resolved (or rejected). For this scenario, use
On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');32HistoryVersionChangesv15. 14. 0, v14. 18. 0
The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 argument supports import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();9, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();0, and import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();1
v14. 0. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter won't coerce unsupported input to strings anymore
v10. 0. 0Ditambahkan. v10. 0. 0
Asynchronously writes data to a file, replacing the file if it already exists. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string, a buffer, an , or an object. The promise is resolved with no arguments upon success
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7
The has to support writing
It is unsafe to use import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();3 multiple times on the same file without waiting for the promise to be resolved (or rejected)
If one or more import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');07 calls are made on a file handle and then a import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();3 call is made, the data will be written from the current position till the end of the file. It doesn't always write from the beginning of the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');44Write an array of s to the file
The promise is resolved with an object containing a two properties
It is unsafe to call import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');45 multiple times on the same file without waiting for the promise to be resolved (or rejected)
Di Linux, penulisan posisi tidak berfungsi saat file dibuka dalam mode penambahan. The kernel ignores the position argument and always appends the data to the end of the file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');46
Tests a user's permissions for the file or directory specified by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 argument is an optional integer that specifies the accessibility checks to be performed. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 should be either the value import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');50 or a mask consisting of the bitwise OR of any of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');51, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');52, and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');53 (e. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');54). Check for possible values of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48
If the accessibility check is successful, the promise is resolved with no value. If any of the accessibility checks fail, the promise is rejected with an object. The following example checks if the file import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');56 can be read and written by the current process
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }Using import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');57 to check for the accessibility of a file before calling import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();3 is not recommended. Doing so introduces a race condition, since other processes may change the file's state between the two calls. Instead, user code should open/read/write the file directly and handle the error raised if the file is not accessible
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');59
Asynchronously append data to a file, creating the file if it does not yet exist. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string or a
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 may be specified as a that has been opened for appending (using import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();3)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');67
Changes the permissions of a file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');68
Changes the ownership of a file
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');69
HistoryVersionChangesv14. 0. 0
Changed import * as fs from 'node:fs';const fs = require('node:fs');10 argument to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 and imposed stricter type validation
v10. 0. 0Ditambahkan. v10. 0. 0
Asynchronously copies import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73. By default, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 is overwritten if it already exists
No guarantees are made about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, an attempt will be made to remove the destination
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');85
HistoryVersionChangesv17. 6. 0, v16. 15. 0
Menerima opsi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_86 tambahan untuk menentukan apakah akan melakukan resolusi jalur untuk symlink
v16. 7. 0Ditambahkan. v16. 7. 0
Secara asinkron menyalin seluruh struktur direktori dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 ke import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73, termasuk subdirektori dan file
When copying a directory to another directory, globs are not supported and behavior is similar to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });18
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_19
Tidak digunakan lagi sejak. v10. 0. 0
Mengubah izin pada tautan simbolik
Metode ini hanya diterapkan di macOS
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_20
HistoryVersionChangesv10. 6. 0
This API is no longer deprecated
v10. 0. 0Ditambahkan. v10. 0. 0
Mengubah kepemilikan pada tautan simbolik
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_21
Added in. v14. 5. 0, v12. 19. 0
Mengubah waktu akses dan modifikasi file dengan cara yang sama seperti , dengan perbedaan bahwa jika jalur merujuk ke tautan simbolis, maka tautan tersebut tidak direferensikan. instead, the timestamps of the symbolic link itself are changed
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });23
Membuat tautan baru dari import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_24 ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25. Lihat dokumentasi POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });26 untuk detail lebih lanjut
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_27
HistoryVersionChangesv10. 5. 0
Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Ditambahkan. v10. 0. 0
Setara dengan kecuali import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 mengacu pada tautan simbolik, dalam hal ini tautan itu sendiri adalah stat-ed, bukan file yang dirujuknya. Lihat dokumen POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_31 untuk detail lebih lanjut
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });32
Secara asinkron membuat direktori
Argumen import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 opsional dapat berupa bilangan bulat yang menentukan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_48 (izin dan sticky bits), atau objek dengan properti import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 dan properti import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 yang menunjukkan apakah direktori induk harus dibuat. Memanggil import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_37 saat import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 adalah direktori yang ada menghasilkan penolakan hanya jika import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 salah
import * as fs from 'node:fs';const fs = require('node:fs');0import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });40
HistoryVersionChangesv16. 5. 0, v14. 18. 0
Parameter import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 sekarang menerima string kosong
v10. 0. 0Ditambahkan. v10. 0. 0
Membuat direktori sementara yang unik. Nama direktori unik dihasilkan dengan menambahkan enam karakter acak di akhir import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 yang disediakan. Karena inkonsistensi platform, hindari membuntuti import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });43 karakter dalam import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41. Beberapa platform, terutama BSD, dapat mengembalikan lebih dari enam karakter acak, dan mengganti import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });43 karakter di import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 dengan karakter acak
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use
import * as fs from 'node:fs';const fs = require('node:fs');1Metode import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });49 akan menambahkan enam karakter yang dipilih secara acak langsung ke string import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41. Misalnya, diberi direktori import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_51, jika tujuannya adalah untuk membuat direktori sementara di dalam import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });51, import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 harus diakhiri dengan pemisah jalur khusus platform tambahan (import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });54)
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });55
HistoryVersionChangesv11. 1. 0
Argumen import * as fs from 'node:fs';const fs = require('node:fs');_10 sekarang opsional dan default ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });57
v10. 0. 0Ditambahkan. v10. 0. 0
Buka a
Lihat dokumentasi POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_58 untuk detail lebih lanjut
Beberapa karakter (import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_59) dicadangkan di bawah Windows seperti yang didokumentasikan oleh File Penamaan, Jalur, dan Ruang Nama. Under NTFS, if the filename contains a colon, Node. js will open a file system stream, as described by this MSDN page
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_60
HistoryVersionChangesv13. 1. 0, v12. 16. 0
Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });61 diperkenalkan
v12. 12. 0Added in. v12. 12. 0
Buka direktori secara asinkron untuk pemindaian berulang. Lihat dokumentasi POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });62 untuk detail lebih lanjut
Membuat , yang berisi semua fungsi lebih lanjut untuk membaca dari dan membersihkan direktori
Opsi import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 menetapkan pengkodean untuk import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 saat membuka direktori dan operasi baca selanjutnya
Contoh menggunakan async iterasi
import * as fs from 'node:fs';const fs = require('node:fs');2Saat menggunakan iterator async, objek akan ditutup secara otomatis setelah iterator keluar
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_65
HistoryVersionChangesv10. 11. 0
Opsi baru import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_66 telah ditambahkan
v10. 0. 0Ditambahkan. v10. 0. 0
Membaca isi direktori
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the filenames. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the filenames returned will be passed as objects
If import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });71 is set to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the resolved array will contain objects
import * as fs from 'node:fs';const fs = require('node:fs');3import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_73
HistoryVersionChangesv15. 2. 0, v14. 17. 0
Argumen opsi mungkin menyertakan AbortSignal untuk membatalkan permintaan readFile yang sedang berlangsung
v10. 0. 0Ditambahkan. v10. 0. 0
Asynchronously reads the entire contents of a file
If no encoding is specified (using import * as fs from 'node:fs';const fs = require('node:fs');65), the data is returned as a object. Jika tidak, data akan berupa string
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the encoding
When the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 is a directory, the behavior of import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });77 is platform-specific. Di macOS, Linux, dan Windows, janji akan ditolak dengan kesalahan. Pada FreeBSD, representasi dari isi direktori akan dikembalikan
An example of reading a import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });78 file located in the same directory of the running code
import * as fs from 'node:fs';const fs = require('node:fs');_4Dimungkinkan untuk menggugurkan ________6______79 yang sedang berlangsung menggunakan. If a request is aborted the promise returned is rejected with an import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });80
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });81 performs
Any specified has to support reading
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_82
Reads the contents of the symbolic link referred to by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. Lihat dokumentasi POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });84 untuk detail lebih lanjut. Janji diselesaikan dengan import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_85 setelah sukses
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the link path returned. Jika import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 disetel ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, jalur tautan yang dikembalikan akan diteruskan sebagai objek
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_90
Menentukan lokasi sebenarnya dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 menggunakan semantik yang sama dengan fungsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });92
Hanya jalur yang dapat dikonversi ke string UTF8 yang didukung
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the path. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the path returned will be passed as a object
On Linux, when Node. js ditautkan dengan musl libc, sistem file procfs harus dipasang pada import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });97 agar fungsi ini berfungsi. Glibc tidak memiliki batasan ini
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_98
Ganti nama import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_99 menjadi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_01
HistoryVersionChangesv16. 0. 0
Menggunakan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_02 pada import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 yang merupakan file tidak lagi diizinkan dan menghasilkan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 pada Windows dan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 pada POSIX
v16. 0. 0Menggunakan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_02 pada import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 yang tidak ada tidak lagi diizinkan dan menghasilkan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04
v16. 0. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 sudah tidak digunakan lagi, menggunakannya akan memicu peringatan penghentian
v14. 14. 0The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 option is deprecated, use import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }11 instead
v13. 3. 0, v12. 16. 0Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_12 diganti namanya menjadi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }13, dan standarnya adalah 0. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_14 telah dihapus, dan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15 menggunakan logika coba lagi yang sama seperti kesalahan lainnya. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 sekarang didukung. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_17 kesalahan sekarang dicoba lagi
v12. 10. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }12, dan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }14 sekarang didukung
v10. 0. 0Ditambahkan. v10. 0. 0
Menghapus direktori yang diidentifikasi oleh import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47
Menggunakan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_42 pada file (bukan direktori) mengakibatkan janji ditolak dengan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 pada Windows dan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 pada POSIX
To get a behavior similar to the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }45 Unix command, use with options import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }47
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_48
Menghapus file dan direktori (dimodelkan pada utilitas standar POSIX import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }73)
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_74
HistoryVersionChangesv10. 5. 0
Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Ditambahkan. v10. 0. 0
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_76
HistoryVersionChangesv19. 0. 0
Jika argumen import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 adalah import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 atau dihilangkan, Node. js akan otomatis mendeteksi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_79 mengetik dan secara otomatis memilih import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }80 atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }81
v10. 0. 0Ditambahkan. v10. 0. 0
Membuat tautan simbolik
Argumen import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_77 hanya digunakan pada platform Windows dan dapat berupa salah satu dari import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }83, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84, atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }85. Jika argumen import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 bukan string, Node. js akan mendeteksi secara otomatis import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_79 mengetik dan menggunakan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84 atau import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }83. Jika import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_79 tidak ada, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84 akan digunakan. Titik persimpangan Windows mengharuskan jalur tujuan mutlak. Saat menggunakan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_85, argumen ________32______79 akan secara otomatis dinormalisasi ke jalur absolut
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_94
Memotong (memperpendek atau memperpanjang panjang) konten pada import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 hingga import * as fs from 'node:fs';const fs = require('node:fs');85 byte
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_97
If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 refers to a symbolic link, then the link is removed without affecting the file or directory to which that link refers. Jika import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 merujuk ke jalur file yang bukan tautan simbolik, file tersebut akan dihapus. Lihat dokumentasi POSIX import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });00 untuk detail lebih lanjut
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_01
Ubah stempel waktu sistem file dari objek yang direferensikan oleh import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47
Argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });03 dan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });04 mengikuti aturan ini
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_11
Ditambahkan. v15. 9. 0, v14. 18. 0
Mengembalikan async iterator yang mengawasi perubahan pada import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12, di mana import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 adalah file atau direktori
import * as fs from 'node:fs';const fs = require('node:fs');5Pada sebagian besar platform, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_23 dikeluarkan setiap kali nama file muncul atau menghilang di direktori
Semua untuk import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_24 juga berlaku untuk import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });25
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });26
HistoryVersionChangesv15. 14. 0, v14. 18. 0
The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 argument supports import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();9, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();0, and import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();1
v15. 2. 0, v14. 17. 0Argumen opsi mungkin menyertakan AbortSignal untuk membatalkan permintaan writeFile yang sedang berlangsung
v14. 0. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter won't coerce unsupported input to strings anymore
v10. 0. 0Ditambahkan. v10. 0. 0
Secara asinkron menulis data ke file, mengganti file jika sudah ada. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string, a buffer, an , or an object
Opsi import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 diabaikan jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 adalah buffer
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the encoding
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
Setiap ditentukan harus mendukung penulisan
Tidak aman untuk menggunakan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_38 beberapa kali pada file yang sama tanpa menunggu janji diselesaikan
Demikian pula dengan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_39 - import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });40 adalah metode praktis yang melakukan beberapa panggilan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });41 secara internal untuk menulis buffer yang diteruskan ke sana. Untuk kode sensitif kinerja, pertimbangkan untuk menggunakan atau
Anda dapat menggunakan an untuk membatalkan ________0______38. Pembatalan adalah "usaha terbaik", dan sejumlah data kemungkinan masih akan ditulis
Membatalkan permintaan yang sedang berlangsung tidak membatalkan permintaan sistem operasi individu melainkan buffering internal import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });45 melakukan
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_46
Ditambahkan. v18. 4. 0, v16. 17. 0
Mengembalikan objek yang berisi konstanta yang biasa digunakan untuk operasi sistem file. Objeknya sama dengan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_47. Lihat untuk detail lebih lanjut
API panggilan balik
Callback API melakukan semua operasi secara asinkron, tanpa memblokir loop peristiwa, lalu menjalankan fungsi callback setelah selesai atau terjadi kesalahan
Callback API menggunakan Node yang mendasarinya. js threadpool untuk melakukan operasi sistem file dari utas loop acara. Operasi ini tidak disinkronkan atau threadsafe. Kehati-hatian harus dilakukan saat melakukan beberapa modifikasi bersamaan pada file yang sama atau kerusakan data dapat terjadi
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_48
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v6. 3. 0Konstanta seperti import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });55, dll yang hadir langsung pada import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 dipindahkan ke import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });47 sebagai penghentian lunak. Jadi untuk Node. js import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_58 gunakan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 untuk mengakses konstanta tersebut, atau lakukan sesuatu seperti import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });60 untuk bekerja dengan semua versi
v0. 11. 15Ditambahkan. v0. 11. 15
Tests a user's permissions for the file or directory specified by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 argument is an optional integer that specifies the accessibility checks to be performed. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 should be either the value import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');50 or a mask consisting of the bitwise OR of any of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');51, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');52, and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');53 (e. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');54). Check for possible values of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48
Argumen terakhir, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49, adalah fungsi panggilan balik yang dipanggil dengan kemungkinan argumen kesalahan. Jika ada pemeriksaan aksesibilitas yang gagal, argumen kesalahan akan berupa objek import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });10. Contoh berikut memeriksa apakah import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_78 ada, dan apakah dapat dibaca atau ditulis
Jangan gunakan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_73 untuk memeriksa aksesibilitas file sebelum menelepon import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75, atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76. Melakukannya memperkenalkan kondisi balapan, karena proses lain dapat mengubah status file di antara dua panggilan. Sebaliknya, kode pengguna harus membuka/membaca/menulis file secara langsung dan menangani kesalahan yang muncul jika file tidak dapat diakses
tulis (TIDAK DIREKOMENDASIKAN)
import * as fs from 'node:fs';const fs = require('node:fs');6menulis (DISARANKAN)
import * as fs from 'node:fs';const fs = require('node:fs');7baca (TIDAK DIREKOMENDASIKAN)
import * as fs from 'node:fs';const fs = require('node:fs');_8baca (DIREKOMENDASIKAN)
import * as fs from 'node:fs';const fs = require('node:fs');_9Contoh "tidak direkomendasikan" di atas memeriksa aksesibilitas dan kemudian menggunakan file;
Secara umum, periksa aksesibilitas suatu file hanya jika file tersebut tidak akan digunakan secara langsung, misalnya ketika aksesibilitasnya merupakan sinyal dari proses lain
Di Windows, kebijakan kontrol akses (ACL) pada direktori dapat membatasi akses ke file atau direktori. Fungsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });73, bagaimanapun, tidak memeriksa ACL dan karena itu dapat melaporkan bahwa jalur dapat diakses meskipun ACL membatasi pengguna untuk membaca atau menulis ke sana
import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_78
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v7. 0. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan tidak akan pernah dimodifikasi
v5. 0. 0Parameter import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_81 dapat menjadi deskriptor file sekarang
v0. 6. 7Ditambahkan. v0. 6. 7
Asynchronously append data to a file, creating the file if it does not yet exist. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string or a
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');0Jika import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 adalah sebuah string, maka itu menentukan pengkodean
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');1import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat ditentukan sebagai deskriptor file numerik yang telah dibuka untuk ditambahkan (menggunakan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64 atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });93). Deskriptor file tidak akan ditutup secara otomatis
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');2import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_94
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 30Ditambahkan. v0. 1. 30
Secara asinkron mengubah izin file. Tidak ada argumen selain kemungkinan pengecualian yang diberikan pada callback penyelesaian
Lihat dokumentasi POSIX import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_7 untuk detail lebih lanjut
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_3Modus berkasArgumen import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_48 yang digunakan dalam metode import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();06 dan import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();07 adalah bitmask numerik yang dibuat menggunakan logika OR dari konstanta berikut
ConstantOctalDescriptionimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();08import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();09read by ownerimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();10import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();11write by ownerimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();12import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();13execute/search by ownerimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();14import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();15read by groupimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();16import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();17write by groupimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();18import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();19execute/search by groupimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();20import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();21read by othersimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();22import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();23write by othersimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();24import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();25execute/search by othersMetode yang lebih mudah untuk membangun import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_48 adalah dengan menggunakan urutan tiga digit oktal (e. g. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_27). Digit paling kiri (import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_28 pada contoh), menentukan izin untuk pemilik file. Digit tengah (import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_29 dalam contoh), menentukan izin untuk grup. Digit paling kanan (import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();30 dalam contoh), menentukan izin untuk orang lain
NumberDescriptionimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_28baca, tulis, dan jalankanimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();29baca dan tulisimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();30baca dan jalankanimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();34baca sajaimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();35tulis dan jalankanimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();36tulis sajaimport { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();37jalankan saja________2______39tidak ada izinMisalnya, nilai oktal import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_39 artinya
Saat menggunakan angka mentah di mana mode file diharapkan, nilai apa pun yang lebih besar dari import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();40 dapat mengakibatkan perilaku khusus platform yang tidak didukung untuk bekerja secara konsisten. Oleh karena itu konstanta seperti import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();41, import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();42, atau import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();43 tidak diekspos di import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });47
Peringatan. di Windows hanya izin tulis yang dapat diubah, dan perbedaan antara izin grup, pemilik, atau lainnya tidak diterapkan
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_45
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 97Ditambahkan. v0. 1. 97
Secara asinkron mengubah pemilik dan grup file. Tidak ada argumen selain kemungkinan pengecualian yang diberikan pada callback penyelesaian
Lihat dokumentasi POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }2 untuk detail lebih lanjut
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_56
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v15. 9. 0, v14. 17. 0Callback default sekarang digunakan jika tidak tersedia
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Menutup deskriptor file. Tidak ada argumen selain kemungkinan pengecualian yang diberikan pada callback penyelesaian
Memanggil import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_63 pada deskriptor file apa pun (import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64) yang sedang digunakan melalui operasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 lainnya dapat menyebabkan perilaku yang tidak ditentukan
Lihat dokumentasi POSIX import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_66 untuk detail lebih lanjut
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_67
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v14. 0. 0Changed import * as fs from 'node:fs';const fs = require('node:fs');10 argument to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 and imposed stricter type validation
v8. 5. 0Ditambahkan. v8. 5. 0
Secara asinkron menyalin import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 ke import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73. Secara default, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_73 akan ditimpa jika sudah ada. Tidak ada argumen selain kemungkinan pengecualian yang diberikan ke fungsi callback. Node. js tidak memberikan jaminan tentang atomisitas operasi penyalinan. Jika terjadi kesalahan setelah file tujuan dibuka untuk penulisan, Node. js akan mencoba menghapus tujuan
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 adalah bilangan bulat opsional yang menentukan perilaku operasi penyalinan. It is possible to create a mask consisting of the bitwise OR of two or more values (e. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_75)
import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_82
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v17. 6. 0, v16. 15. 0Menerima opsi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_86 tambahan untuk menentukan apakah akan melakukan resolusi jalur untuk symlink
v16. 7. 0Ditambahkan. v16. 7. 0
Secara asinkron menyalin seluruh struktur direktori dari import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 ke import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73, termasuk subdirektori dan file
When copying a directory to another directory, globs are not supported and behavior is similar to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });18
import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_19
HistoryVersionChangesv16. 10. 0
Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 tidak memerlukan metode import * as fs from 'node:fs';const fs = require('node:fs');11 jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 disediakan
v16. 10. 0Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 tidak perlu import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 metode jika import * as fs from 'node:fs';const fs = require('node:fs');02 adalah import * as fs from 'node:fs';const fs = require('node:fs');01
v15. 4. 0Opsi import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 menerima argumen FileHandle
v14. 0. 0Ubah import * as fs from 'node:fs';const fs = require('node:fs');_00 default menjadi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97
v13. 6. 0, v12. 17. 0Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 memungkinkan mengesampingkan implementasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 yang digunakan
v12. 10. 0Aktifkan opsi import * as fs from 'node:fs';const fs = require('node:fs');_00
v11. 0. 0Terapkan batasan baru pada import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_9 dan import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }0, berikan kesalahan yang lebih tepat jika kami tidak dapat menangani nilai input secara wajar
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan tidak akan pernah dimodifikasi
v2. 3. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan bisa menjadi string sekarang
v0. 1. 31Ditambahkan. v0. 1. 31
Unlike the 16 KiB default import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }6 for a , the stream returned by this method has a default import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }6 of 64 KiB
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 dapat menyertakan nilai import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 dan import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }0 untuk membaca rentang byte dari file, bukan seluruh file. Baik import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 dan import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }0 inklusif dan mulai menghitung dari 0, nilai yang diizinkan berada dalam rentang [0, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }3]. Jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 ditentukan dan import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 dihilangkan atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();51 dibaca secara berurutan dari posisi file saat ini. import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 dapat berupa salah satu dari yang diterima oleh
Jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 ditentukan, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();54 akan mengabaikan argumen import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 dan akan menggunakan deskriptor file yang ditentukan. Ini berarti bahwa tidak ada peristiwa import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_56 yang akan dipancarkan. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 harus diblokir;
Jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 menunjuk ke perangkat karakter yang hanya mendukung pembacaan pemblokiran (seperti keyboard atau kartu suara), operasi pembacaan tidak selesai hingga data tersedia. Ini dapat mencegah proses keluar dan aliran menutup secara alami
By default, the stream will emit a import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5 event after it has been destroyed. Set the import * as fs from 'node:fs';const fs = require('node:fs');00 option to import * as fs from 'node:fs';const fs = require('node:fs');01 to change this behavior
Dengan memberikan opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_56, implementasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 yang sesuai untuk import * as fs from 'node:fs';const fs = require('node:fs');11, import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();66, dan import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 dapat diganti. Saat memberikan opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56, penggantian untuk import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();66 diperlukan. Jika tidak ada import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 yang diberikan, penggantian untuk import * as fs from 'node:fs';const fs = require('node:fs');11 juga diperlukan. Jika import * as fs from 'node:fs';const fs = require('node:fs');02 adalah import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, penggantian untuk import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 juga diperlukan
If import * as fs from 'node:fs';const fs = require('node:fs');02 is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak. If import * as fs from 'node:fs';const fs = require('node:fs');02 is set to true (default behavior), on import * as fs from 'node:fs';const fs = require('node:fs');04 or import * as fs from 'node:fs';const fs = require('node:fs');05 the file descriptor will be closed automatically
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 menyetel mode file (izin dan sticky bit), tetapi hanya jika file dibuat
An example to read the last 10 bytes of a file which is 100 bytes long
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_4If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the encoding
import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_81
HistoryVersionChangesv16. 10. 0
Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 tidak memerlukan metode import * as fs from 'node:fs';const fs = require('node:fs');11 jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 disediakan
v16. 10. 0Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 tidak perlu import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 metode jika import * as fs from 'node:fs';const fs = require('node:fs');02 adalah import * as fs from 'node:fs';const fs = require('node:fs');01
v15. 4. 0Opsi import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 menerima argumen FileHandle
v14. 0. 0Ubah import * as fs from 'node:fs';const fs = require('node:fs');_00 default menjadi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97
v13. 6. 0, v12. 17. 0Opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 memungkinkan mengesampingkan implementasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 yang digunakan
v12. 10. 0Aktifkan opsi import * as fs from 'node:fs';const fs = require('node:fs');_00
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan tidak akan pernah dimodifikasi
v5. 5. 0Opsi import * as fs from 'node:fs';const fs = require('node:fs');_02 didukung sekarang
v2. 3. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan bisa menjadi string sekarang
v0. 1. 31Ditambahkan. v0. 1. 31
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 juga dapat menyertakan opsi import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }9 untuk memungkinkan penulisan data di beberapa posisi melewati awal file, nilai yang diizinkan berada di kisaran [0, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }3]. Memodifikasi file daripada menggantinya mungkin memerlukan opsi import * as fs from 'node:fs';const fs = require('node:fs');10 untuk disetel ke import * as fs from 'node:fs';const fs = require('node:fs');12 daripada default import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }06. import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 dapat berupa salah satu dari yang diterima oleh
If import * as fs from 'node:fs';const fs = require('node:fs');02 is set to true (default behavior) on import * as fs from 'node:fs';const fs = require('node:fs');04 or import * as fs from 'node:fs';const fs = require('node:fs');17 the file descriptor will be closed automatically. If import * as fs from 'node:fs';const fs = require('node:fs');02 is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak
By default, the stream will emit a import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();5 event after it has been destroyed. Set the import * as fs from 'node:fs';const fs = require('node:fs');00 option to import * as fs from 'node:fs';const fs = require('node:fs');01 to change this behavior
Dengan memberikan opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_56, implementasi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 yang sesuai untuk import * as fs from 'node:fs';const fs = require('node:fs');11, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });41, import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }19, dan import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 dapat diganti. Mengganti import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }21 tanpa import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');45 dapat mengurangi kinerja karena beberapa pengoptimalan (import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }23) akan dinonaktifkan. Saat memberikan opsi import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_56, penggantian untuk setidaknya satu dari import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });41 dan import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }19 diperlukan. Jika tidak ada opsi import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 yang disediakan, penggantian untuk import * as fs from 'node:fs';const fs = require('node:fs');11 juga diperlukan. Jika import * as fs from 'node:fs';const fs = require('node:fs');02 adalah import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, penggantian untuk import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();24 juga diperlukan
Seperti , jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 ditentukan, akan mengabaikan argumen import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 dan akan menggunakan deskriptor file yang ditentukan. Ini berarti bahwa tidak ada peristiwa import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_56 yang akan dipancarkan. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_64 harus diblokir;
If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is a string, then it specifies the encoding
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }38
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v1. 0. 0Tidak digunakan lagi sejak. v1. 0. 0
v0. 0. 2Ditambahkan. v0. 0. 2
Uji apakah jalur yang diberikan ada atau tidak dengan memeriksa dengan sistem file. Then call the import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 argument with either true or false
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');5The parameters for this callback are not consistent with other Node. js callbacks. Normally, the first parameter to a Node. js callback is an import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }46 parameter, optionally followed by other parameters. The import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }47 callback has only one boolean parameter. This is one reason import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });73 is recommended instead of import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }47
Using import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }47 to check for the existence of a file before calling import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75, or import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 is not recommended. Doing so introduces a race condition, since other processes may change the file's state between the two calls. Instead, user code should open/read/write the file directly and handle the error raised if the file does not exist
tulis (TIDAK DIREKOMENDASIKAN)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');6menulis (DISARANKAN)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');7baca (TIDAK DIREKOMENDASIKAN)
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');8baca (DIREKOMENDASIKAN)
import * as fs from 'node:fs';const fs = require('node:fs');_9The "not recommended" examples above check for existence and then use the file; the "recommended" examples are better because they use the file directly and handle the error, if any
In general, check for the existence of a file only if the file won't be used directly, for example when its existence is a signal from another process
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }54
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 4. 7Ditambahkan. v0. 4. 7
Sets the permissions on the file. No arguments other than a possible exception are given to the completion callback
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }61 documentation for more detail
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }62
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 4. 7Ditambahkan. v0. 4. 7
Sets the owner of the file. No arguments other than a possible exception are given to the completion callback
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }69 documentation for more detail
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }70
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 96Added in. v0. 1. 96
Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');24 documentation for details. No arguments other than a possible exception are given to the completion callback
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }78
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 5. 0Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 95Added in. v0. 1. 95
Invokes the callback with the for the file descriptor
See the POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }86 documentation for more detail
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }87
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 96Added in. v0. 1. 96
Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX import * as fs from 'node:fs';const fs = require('node:fs');83 documentation for more detail. No arguments other than a possible exception are given to the completion callback
import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }95
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 8. 6Added in. v0. 8. 6
Truncates the file descriptor. No arguments other than a possible exception are given to the completion callback
See the POSIX import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }02 documentation for more detail
If the file referred to by the file descriptor was larger than import * as fs from 'node:fs';const fs = require('node:fs');85 bytes, only the first import * as fs from 'node:fs';const fs = require('node:fs');85 bytes will be retained in the file
For example, the following program retains only the first four bytes of the file
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });0If the file previously was shorter than import * as fs from 'node:fs';const fs = require('node:fs');85 bytes, it is extended, and the extended part is filled with null bytes (import * as fs from 'node:fs';const fs = require('node:fs');88)
If import * as fs from 'node:fs';const fs = require('node:fs');85 is negative then import * as fs from 'node:fs';const fs = require('node:fs');39 will be used
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }09
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v4. 1. 0Numeric strings, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08 are now allowed time specifiers
v0. 4. 2Added in. v0. 4. 2
Change the file system timestamps of the object referenced by the supplied file descriptor. See
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }19
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v16. 0. 0The error returned may be an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }23 if more than one error is returned
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 4. 7Deprecated since. v0. 4. 7
Changes the permissions on a symbolic link. No arguments other than a possible exception are given to the completion callback
Metode ini hanya diterapkan di macOS
See the POSIX import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }27 documentation for more detail
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }28
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 6. 0This API is no longer deprecated
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 4. 7Documentation-only deprecation
Set the owner of the symbolic link. No arguments other than a possible exception are given to the completion callback
See the POSIX import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }35 documentation for more detail
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }36
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v14. 5. 0, v12. 19. 0Added in. v14. 5. 0, v12. 19. 0
Mengubah waktu akses dan modifikasi file dengan cara yang sama seperti , dengan perbedaan bahwa jika jalur merujuk ke tautan simbolis, maka tautan tersebut tidak direferensikan. instead, the timestamps of the symbolic link itself are changed
No arguments other than a possible exception are given to the completion callback
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }41
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });24 and import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Support is currently still experimental
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 31Ditambahkan. v0. 1. 31
Membuat tautan baru dari import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_24 ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25. See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });26 documentation for more detail. No arguments other than a possible exception are given to the completion callback
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }55
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 5. 0Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 30Ditambahkan. v0. 1. 30
Retrieves the for the symbolic link referred to by the path. The callback gets two arguments import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }66 where import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }67 is a object. import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }68 is identical to import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }69, except that if import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 is a symbolic link, then the link itself is stat-ed, not the file that it refers to
See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });31 documentation for more details
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }72
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v13. 11. 0, v12. 17. 0In import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 mode, the callback now receives the first created path as an argument
v10. 12. 0The second argument can now be an import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object with import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 properties
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 8Added in. v0. 1. 8
Secara asinkron membuat direktori
The callback is given a possible exception and, if import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the first directory path created, import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }88. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 can still be import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6 when import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, if no directory was created
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be an integer specifying import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 (permission and sticky bits), or an object with a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 property and a import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 property indicating whether parent directories should be created. Calling import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }97 when import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 is a directory that exists results in an error only when import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 is false
On Windows, using import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }97 on the root directory even with recursion will result in an error
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');001 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');002
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v16. 5. 0, v14. 18. 0Parameter import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 sekarang menerima string kosong
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v6. 2. 1The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 parameter is optional now
v5. 10. 0Ditambahkan. v5. 10. 0
Membuat direktori sementara yang unik
Menghasilkan enam karakter acak untuk ditambahkan di belakang import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 yang diperlukan untuk membuat direktori sementara yang unik. Karena inkonsistensi platform, hindari membuntuti import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });43 karakter dalam import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41. Beberapa platform, terutama BSD, dapat mengembalikan lebih dari enam karakter acak, dan mengganti import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });43 karakter di import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 dengan karakter acak
Jalur direktori yang dibuat diteruskan sebagai string ke parameter kedua callback
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use
Metode import * as fs from 'node:fs';const fs = require('node:fs');_018 akan menambahkan enam karakter yang dipilih secara acak langsung ke string import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41. Misalnya, diberi direktori import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_51, jika tujuannya adalah untuk membuat direktori sementara di dalam import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });51, import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });41 harus diakhiri dengan pemisah jalur khusus platform tambahan (import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });54)
import * as fs from 'node:fs';const fs = require('node:fs');_024
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v11. 1. 0Argumen import * as fs from 'node:fs';const fs = require('node:fs');_10 sekarang opsional dan default ke import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });57
v9. 9. 0The import * as fs from 'node:fs';const fs = require('node:fs');030 and import * as fs from 'node:fs';const fs = require('node:fs');031 flags are supported now
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 0. 2Ditambahkan. v0. 0. 2
File asinkron terbuka. See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });58 documentation for more details
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 sets the file mode (permission and sticky bits), but only if the file was created. On Windows, only the write permission can be manipulated; see
The callback gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');038
Beberapa karakter (import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_59) dicadangkan di bawah Windows seperti yang didokumentasikan oleh File Penamaan, Jalur, dan Ruang Nama. Under NTFS, if the filename contains a colon, Node. js will open a file system stream, as described by this MSDN page
Functions based on import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64 exhibit this behavior as well. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75, etc
import * as fs from 'node:fs';const fs = require('node:fs');043
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v13. 1. 0, v12. 16. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });61 diperkenalkan
v12. 12. 0Added in. v12. 12. 0
Asynchronously open a directory. See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });62 documentation for more details
Membuat , yang berisi semua fungsi lebih lanjut untuk membaca dari dan membersihkan direktori
Opsi import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 menetapkan pengkodean untuk import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 saat membuka direktori dan operasi baca selanjutnya
import * as fs from 'node:fs';const fs = require('node:fs');051
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 10. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056, or a import * as fs from 'node:fs';const fs = require('node:fs');057
v7. 4. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be a import * as fs from 'node:fs';const fs = require('node:fs');059
v6. 0. 0The import * as fs from 'node:fs';const fs = require('node:fs');30 parameter can now be import * as fs from 'node:fs';const fs = require('node:fs');39
v0. 0. 2Ditambahkan. v0. 0. 2
Read data from the file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64
Panggilan balik diberikan tiga argumen, import * as fs from 'node:fs';const fs = require('node:fs');074
If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero
If this method is invoked as its ed version, it returns a promise for an import * as fs from 'node:fs';const fs = require('node:fs');076 with import * as fs from 'node:fs';const fs = require('node:fs');077 and import * as fs from 'node:fs';const fs = require('node:fs');28 properties
import * as fs from 'node:fs';const fs = require('node:fs');079
HistoryVersionChangesv13. 11. 0, v12. 17. 0
Options object can be passed in to make buffer, offset, length, and position optional
v13. 11. 0, v12. 17. 0Added in. v13. 11. 0, v12. 17. 0
Similar to the function, this version takes an optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object. If no import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object is specified, it will default with the above values
import * as fs from 'node:fs';const fs = require('node:fs');083
Ditambahkan. v18. 2. 0, v16. 17. 0
Similar to the function, this version takes an optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object. If no import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object is specified, it will default with the above values
import * as fs from 'node:fs';const fs = require('node:fs');087
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 10. 0Opsi baru import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });_66 telah ditambahkan
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v6. 0. 0The import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 parameter was added
v0. 1. 8Added in. v0. 1. 8
Reads the contents of a directory. The callback gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');099 where import * as fs from 'node:fs';const fs = require('node:fs');100 is an array of the names of the files in the directory excluding import * as fs from 'node:fs';const fs = require('node:fs');101 and import * as fs from 'node:fs';const fs = require('node:fs');102
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');103 documentation for more details
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the filenames passed to the callback. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the filenames returned will be passed as objects
If import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });71 is set to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the import * as fs from 'node:fs';const fs = require('node:fs');100 array will contain objects
import * as fs from 'node:fs';const fs = require('node:fs');111
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v16. 0. 0The error returned may be an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }23 if more than one error is returned
v15. 2. 0, v14. 17. 0Argumen opsi mungkin menyertakan AbortSignal untuk membatalkan permintaan readFile yang sedang berlangsung
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v5. 1. 0The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 will always be called with import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5 as the import * as fs from 'node:fs';const fs = require('node:fs');124 parameter in case of success
v5. 0. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameter can be a file descriptor now
v0. 1. 29Added in. v0. 1. 29
Asynchronously reads the entire contents of a file
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });1The callback is passed two arguments import * as fs from 'node:fs';const fs = require('node:fs');126, where import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 is the contents of the file
If no encoding is specified, then the raw buffer is returned
Jika import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 adalah sebuah string, maka itu menentukan pengkodean
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });2When the path is a directory, the behavior of import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75 and is platform-specific. On macOS, Linux, and Windows, an error will be returned. On FreeBSD, a representation of the directory's contents will be returned
It is possible to abort an ongoing request using an import * as fs from 'node:fs';const fs = require('node:fs');131. If a request is aborted the callback is called with an import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });80
The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75 function buffers the entire file. To minimize memory costs, when possible prefer streaming via import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();51
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });81 performs
File descriptorsThe import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75 method asynchronously reads the contents of a file into memory one chunk at a time, allowing the event loop to turn between each chunk. This allows the read operation to have less impact on other activity that may be using the underlying libuv thread pool but means that it will take longer to read a complete file into memory
The additional read overhead can vary broadly on different systems and depends on the type of file being read. If the file type is not a regular file (a pipe for instance) and Node. js is unable to determine an actual file size, each read operation will load on 64 KiB of data. For regular files, each read will process 512 KiB of data
For applications that require as-fast-as-possible reading of file contents, it is better to use import * as fs from 'node:fs';const fs = require('node:fs');080 directly and for application code to manage reading the full contents of the file itself
The Node. js GitHub issue #25741 provides more information and a detailed analysis on the performance of import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75 for multiple file sizes in different Node. js versions
import * as fs from 'node:fs';const fs = require('node:fs');144
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 1. 31Ditambahkan. v0. 1. 31
Reads the contents of the symbolic link referred to by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. The callback gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');155
See the POSIX import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });84 documentation for more details
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the link path passed to the callback. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the link path returned will be passed as a object
import * as fs from 'node:fs';const fs = require('node:fs');161
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v13. 13. 0, v12. 17. 0Added in. v13. 13. 0, v12. 17. 0
Read from a file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 and write to an array of import * as fs from 'node:fs';const fs = require('node:fs');166s using import * as fs from 'node:fs';const fs = require('node:fs');167
import * as fs from 'node:fs';const fs = require('node:fs');31 is the offset from the beginning of the file from where data should be read. If import * as fs from 'node:fs';const fs = require('node:fs');169, the data will be read from the current position
The callback will be given three arguments. import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }46, import * as fs from 'node:fs';const fs = require('node:fs');077, and import * as fs from 'node:fs';const fs = require('node:fs');74. import * as fs from 'node:fs';const fs = require('node:fs');077 is how many bytes were read from the file
If this method is invoked as its ed version, it returns a promise for an import * as fs from 'node:fs';const fs = require('node:fs');076 with import * as fs from 'node:fs';const fs = require('node:fs');077 and import * as fs from 'node:fs';const fs = require('node:fs');74 properties
import * as fs from 'node:fs';const fs = require('node:fs');178
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v8. 0. 0Pipe/Socket resolve support was added
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v6. 4. 0Calling import * as fs from 'node:fs';const fs = require('node:fs');188 now works again for various edge cases on Windows
v6. 0. 0Parameter import * as fs from 'node:fs';const fs = require('node:fs');_189 telah dihapus
v0. 1. 31Ditambahkan. v0. 1. 31
Asynchronously computes the canonical pathname by resolving import * as fs from 'node:fs';const fs = require('node:fs');190, import * as fs from 'node:fs';const fs = require('node:fs');191, and symbolic links
A canonical pathname is not necessarily unique. Hard links and bind mounts can expose a file system entity through many pathnames
This function behaves like import * as fs from 'node:fs';const fs = require('node:fs');192, with some exceptions
The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');195. May use import * as fs from 'node:fs';const fs = require('node:fs');196 to resolve relative paths
Hanya jalur yang dapat dikonversi ke string UTF8 yang didukung
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the path passed to the callback. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the path returned will be passed as a object
If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 resolves to a socket or a pipe, the function will return a system dependent name for that object
import * as fs from 'node:fs';const fs = require('node:fs');202
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v9. 2. 0Added in. v9. 2. 0
Asynchronous import * as fs from 'node:fs';const fs = require('node:fs');192
The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');195
Hanya jalur yang dapat dikonversi ke string UTF8 yang didukung
The optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument can be a string specifying an encoding, or an object with an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 property specifying the character encoding to use for the path passed to the callback. If the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 is set to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });70, the path returned will be passed as a object
On Linux, when Node. js ditautkan dengan musl libc, sistem file procfs harus dipasang pada import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });97 agar fungsi ini berfungsi. Glibc tidak memiliki batasan ini
import * as fs from 'node:fs';const fs = require('node:fs');214
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });99 and import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Support is currently still experimental
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Asynchronously rename file at import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });99 to the pathname provided as import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25. In the case that import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25 already exists, it will be overwritten. If there is a directory at import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });25, an error will be raised instead. No arguments other than a possible exception are given to the completion callback
See also. import * as fs from 'node:fs';const fs = require('node:fs');229
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });3import * as fs from 'node:fs';const fs = require('node:fs');230
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v16. 0. 0Using import * as fs from 'node:fs';const fs = require('node:fs');234 on a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 that is a file is no longer permitted and results in an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error on Windows and an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 error on POSIX
Using import * as fs from 'node:fs';const fs = require('node:fs');234 on a import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 that does not exist is no longer permitted and results in a import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error
v16. 0. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 sudah tidak digunakan lagi, menggunakannya akan memicu peringatan penghentian
v14. 14. 0The import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10 option is deprecated, use import * as fs from 'node:fs';const fs = require('node:fs');243 instead
v13. 3. 0, v12. 16. 0Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_12 diganti namanya menjadi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }13, dan standarnya adalah 0. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_14 telah dihapus, dan kesalahan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }15 menggunakan logika coba lagi yang sama seperti kesalahan lainnya. Opsi import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_16 sekarang didukung. import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_17 kesalahan sekarang dicoba lagi
v12. 10. 0Opsi import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });10, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }12, dan import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }14 sekarang didukung
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameters can be a WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 object using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Asynchronous import * as fs from 'node:fs';const fs = require('node:fs');279. No arguments other than a possible exception are given to the completion callback
Using import * as fs from 'node:fs';const fs = require('node:fs');280 on a file (not a directory) results in an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error on Windows and an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }05 error on POSIX
To get a behavior similar to the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }45 Unix command, use with options import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }47
import * as fs from 'node:fs';const fs = require('node:fs');_286
HistoryVersionChangesv17. 3. 0, v16. 14. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v14. 14. 0Added in. v14. 14. 0
Asynchronously removes files and directories (modeled on the standard POSIX import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }73 utility). No arguments other than a possible exception are given to the completion callback
import * as fs from 'node:fs';const fs = require('node:fs');315
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 5. 0Accepts an additional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object to specify whether the numeric values returned should be bigint
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Asynchronous import * as fs from 'node:fs';const fs = require('node:fs');326. The callback gets two arguments import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }66 where import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }67 is an object
In case of an error, the import * as fs from 'node:fs';const fs = require('node:fs');329 will be one of
Using import * as fs from 'node:fs';const fs = require('node:fs');330 to check for the existence of a file before calling import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });75, or import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 is not recommended. Instead, user code should open/read/write the file directly and handle the error raised if the file is not available
To check if a file exists without manipulating it afterwards, is recommended
For example, given the following directory structure
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });4The next program will check for the stats of the given paths
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });5The resulting output will resemble
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });6import * as fs from 'node:fs';const fs = require('node:fs');335
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v12. 0. 0If the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 argument is left undefined, Node will autodetect import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 type and automatically select import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }80 or import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }81
v7. 6. 0The import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 parameters can be WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 objects using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol. Dukungan saat ini masih eksperimental
v0. 1. 31Ditambahkan. v0. 1. 31
Creates the link called import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47 pointing to import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79. No arguments other than a possible exception are given to the completion callback
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');349 documentation for more details
The import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 argument is only available on Windows and ignored on other platforms. It can be set to import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }83, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84, or import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }85. If the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }77 argument is not a string, Node. js will autodetect import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 type and use import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84 or import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }83. If the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 does not exist, import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }84 will be used. Windows junction points require the destination path to be absolute. When using import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }85, the import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }79 argument will automatically be normalized to absolute path
Relative targets are relative to the link's parent directory
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });7The above example creates a symbolic link import * as fs from 'node:fs';const fs = require('node:fs');362 which points to import * as fs from 'node:fs';const fs = require('node:fs');363 in the same directory
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });8import * as fs from 'node:fs';const fs = require('node:fs');364
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v16. 0. 0The error returned may be an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }23 if more than one error is returned
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 8. 6Added in. v0. 8. 6
Truncates the file. No arguments other than a possible exception are given to the completion callback. A file descriptor can also be passed as the first argument. In this case, import * as fs from 'node:fs';const fs = require('node:fs');372 is called
Passing a file descriptor is deprecated and may result in an error being thrown in the future
See the POSIX import * as fs from 'node:fs';const fs = require('node:fs');373 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');374
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Asynchronously removes a file or symbolic link. No arguments other than a possible exception are given to the completion callback
import * as fs from 'node:fs';const fs = require('node:fs');384 will not work on a directory, empty or otherwise. To remove a directory, use
See the POSIX import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });00 documentation for more details
import * as fs from 'node:fs';const fs = require('node:fs');387
Stop watching for changes on import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12. If import * as fs from 'node:fs';const fs = require('node:fs');389 is specified, only that particular listener is removed. Otherwise, all listeners are removed, effectively stopping watching of import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12
Calling import * as fs from 'node:fs';const fs = require('node:fs');391 with a filename that is not being watched is a no-op, not an error
Using is more efficient than import * as fs from 'node:fs';const fs = require('node:fs');393 and import * as fs from 'node:fs';const fs = require('node:fs');391. import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });24 should be used instead of import * as fs from 'node:fs';const fs = require('node:fs');393 and import * as fs from 'node:fs';const fs = require('node:fs');391 when possible
import * as fs from 'node:fs';const fs = require('node:fs');398
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v8. 0. 0import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });09 are no longer valid time specifiers
v7. 6. 0Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v4. 1. 0Numeric strings, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });07, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });08 are now allowed time specifiers
v0. 4. 2Added in. v0. 4. 2
Ubah stempel waktu sistem file dari objek yang direferensikan oleh import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47
Argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });03 dan import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });04 mengikuti aturan ini
import * as fs from 'node:fs';const fs = require('node:fs');422
HistoryVersionChangesv19. 1. 0
Added recursive support for Linux, AIX and IBMi
v15. 9. 0, v14. 17. 0Added support for closing the watcher with an AbortSignal
v7. 6. 0The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 parameter can be a WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 object using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol
v7. 0. 0Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan tidak akan pernah dimodifikasi
v0. 5. 10Added in. v0. 5. 10
Watch for changes on import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12, where import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 is either a file or a directory
The second argument is optional. If import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 is provided as a string, it specifies the import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7. Otherwise import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 should be passed as an object
The listener callback gets two arguments import * as fs from 'node:fs';const fs = require('node:fs');443. import * as fs from 'node:fs';const fs = require('node:fs');444 is either import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });23 or import * as fs from 'node:fs';const fs = require('node:fs');446, and import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 is the name of the file which triggered the event
Pada sebagian besar platform, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_23 dikeluarkan setiap kali nama file muncul atau menghilang di direktori
The listener callback is attached to the import * as fs from 'node:fs';const fs = require('node:fs');446 event fired by , but it is not the same thing as the import * as fs from 'node:fs';const fs = require('node:fs');446 value of import * as fs from 'node:fs';const fs = require('node:fs');444
If a import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });20 is passed, aborting the corresponding AbortController will close the returned
CaveatsThe import * as fs from 'node:fs';const fs = require('node:fs');453 API is not 100% consistent across platforms, and is unavailable in some situations
On Windows, no events will be emitted if the watched directory is moved or renamed. An import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }28 error is reported when the watched directory is deleted
AvailabilityThis feature depends on the underlying operating system providing a way to be notified of file system changes
If the underlying functionality is not available for some reason, then import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });24 will not be able to function and may throw an exception. For example, watching files or directories can be unreliable, and in some cases impossible, on network file systems (NFS, SMB, etc) or host file systems when using virtualization software such as Vagrant or Docker
It is still possible to use import * as fs from 'node:fs';const fs = require('node:fs');393, which uses stat polling, but this method is slower and less reliable
InodeOn Linux and macOS systems, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });24 resolves the path to an inode and watches the inode. If the watched path is deleted and recreated, it is assigned a new inode. The watch will emit an event for the delete but will continue watching the original inode. Events for the new inode will not be emitted. Ini adalah perilaku yang diharapkan
AIX files retain the same inode for the lifetime of a file. Saving and closing a watched file on AIX will result in two notifications (one for adding new content, and one for truncation)
Filename argumentProviding import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 argument in the callback is only supported on Linux, macOS, Windows, and AIX. Even on supported platforms, import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 is not always guaranteed to be provided. Therefore, don't assume that import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 argument is always provided in the callback, and have some fallback logic if it is import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });5
import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });9import * as fs from 'node:fs';const fs = require('node:fs');469
HistoryVersionChangesv10. 5. 0
The import * as fs from 'node:fs';const fs = require('node:fs');470 option is now supported
v7. 6. 0The import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12 parameter can be a WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 object using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54 protocol
v0. 1. 31Ditambahkan. v0. 1. 31
Watch for changes on import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });12. The callback import * as fs from 'node:fs';const fs = require('node:fs');389 will be called each time the file is accessed
The import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 argument may be omitted. If provided, it should be an object. The import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object may contain a boolean named import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });14 that indicates whether the process should continue to run as long as files are being watched. The import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object may specify an import * as fs from 'node:fs';const fs = require('node:fs');480 property indicating how often the target should be polled in milliseconds
The import * as fs from 'node:fs';const fs = require('node:fs');389 gets two arguments the current stat object and the previous stat object
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }0These stat objects are instances of import * as fs from 'node:fs';const fs = require('node:fs');482. If the import * as fs from 'node:fs';const fs = require('node:fs');470 option is import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');97, the numeric values in these objects are specified as import * as fs from 'node:fs';const fs = require('node:fs');485s
To be notified when the file was modified, not just accessed, it is necessary to compare import * as fs from 'node:fs';const fs = require('node:fs');486 and import * as fs from 'node:fs';const fs = require('node:fs');487
When an import * as fs from 'node:fs';const fs = require('node:fs');488 operation results in an import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }04 error, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0. 10
Using is more efficient than import * as fs from 'node:fs';const fs = require('node:fs');488 and import * as fs from 'node:fs';const fs = require('node:fs');492. import * as fs from 'node:fs';const fs = require('node:fs');453 should be used instead of import * as fs from 'node:fs';const fs = require('node:fs');488 and import * as fs from 'node:fs';const fs = require('node:fs');492 when possible
When a file being watched by import * as fs from 'node:fs';const fs = require('node:fs');393 disappears and reappears, then the contents of import * as fs from 'node:fs';const fs = require('node:fs');497 in the second callback event (the file's reappearance) will be the same as the contents of import * as fs from 'node:fs';const fs = require('node:fs');497 in the first callback event (its disappearance)
This happens when
import * as fs from 'node:fs';const fs = require('node:fs');499
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v14. 0. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter won't coerce unsupported input to strings anymore
v10. 10. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056 or a import * as fs from 'node:fs';const fs = require('node:fs');057
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 4. 0The import * as fs from 'node:fs';const fs = require('node:fs');28 parameter can now be a import * as fs from 'node:fs';const fs = require('node:fs');059
v7. 2. 0The import * as fs from 'node:fs';const fs = require('node:fs');29 and import * as fs from 'node:fs';const fs = require('node:fs');30 parameters are optional now
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 0. 2Ditambahkan. v0. 0. 2
Write import * as fs from 'node:fs';const fs = require('node:fs');28 to the file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64
import * as fs from 'node:fs';const fs = require('node:fs');29 determines the part of the buffer to be written, and import * as fs from 'node:fs';const fs = require('node:fs');30 is an integer specifying the number of bytes to write
import * as fs from 'node:fs';const fs = require('node:fs');31 refers to the offset from the beginning of the file where this data should be written. If import * as fs from 'node:fs';const fs = require('node:fs');169, the data will be written at the current position. See import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');04
The callback will be given three arguments import * as fs from 'node:fs';const fs = require('node:fs');521 where import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27 specifies how many bytes were written from import * as fs from 'node:fs';const fs = require('node:fs');28
If this method is invoked as its ed version, it returns a promise for an import * as fs from 'node:fs';const fs = require('node:fs');076 with import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27 and import * as fs from 'node:fs';const fs = require('node:fs');28 properties
It is unsafe to use import * as fs from 'node:fs';const fs = require('node:fs');528 multiple times on the same file without waiting for the callback. For this scenario, is recommended
Di Linux, penulisan posisi tidak berfungsi saat file dibuka dalam mode penambahan. The kernel ignores the position argument and always appends the data to the end of the file
import * as fs from 'node:fs';const fs = require('node:fs');530
Added in. v18. 3. 0, v16. 17. 0
Write import * as fs from 'node:fs';const fs = require('node:fs');28 to the file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64
Similar to the above import * as fs from 'node:fs';const fs = require('node:fs');533 function, this version takes an optional import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object. If no import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }8 object is specified, it will default with the above values
import * as fs from 'node:fs';const fs = require('node:fs');536
HistoryVersionChangesv19. 0. 0
Passing to the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter an object with an own import * as fs from 'node:fs';const fs = require('node:fs');538 function is no longer supported
v17. 8. 0Melewati parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 dari suatu objek dengan fungsi import * as fs from 'node:fs';const fs = require('node:fs');538 sendiri tidak digunakan lagi
v14. 12. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter will stringify an object with an explicit import * as fs from 'node:fs';const fs = require('node:fs');538 function
v14. 0. 0The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter won't coerce unsupported input to strings anymore
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 2. 0The import * as fs from 'node:fs';const fs = require('node:fs');31 parameter is optional now
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v0. 11. 5Added in. v0. 11. 5
Write import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 to the file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64. If import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 is not a string, an exception is thrown
import * as fs from 'node:fs';const fs = require('node:fs');31 refers to the offset from the beginning of the file where this data should be written. If import * as fs from 'node:fs';const fs = require('node:fs');169 the data will be written at the current position. See import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');04
import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }7 adalah pengkodean string yang diharapkan
The callback will receive the arguments import * as fs from 'node:fs';const fs = require('node:fs');555 where import * as fs from 'node:fs';const fs = require('node:fs');556 specifies how many bytes the passed string required to be written. Bytes written is not necessarily the same as string characters written. See
It is unsafe to use import * as fs from 'node:fs';const fs = require('node:fs');528 multiple times on the same file without waiting for the callback. For this scenario, is recommended
Di Linux, penulisan posisi tidak berfungsi saat file dibuka dalam mode penambahan. The kernel ignores the position argument and always appends the data to the end of the file
On Windows, if the file descriptor is connected to the console (e. g. import * as fs from 'node:fs';const fs = require('node:fs');560 or import * as fs from 'node:fs';const fs = require('node:fs');561) a string containing non-ASCII characters will not be rendered properly by default, regardless of the encoding used. It is possible to configure the console to render UTF-8 properly by changing the active codepage with the import * as fs from 'node:fs';const fs = require('node:fs');562 command. See the chcp docs for more details
import * as fs from 'node:fs';const fs = require('node:fs');563
HistoryVersionChangesv19. 0. 0
Passing to the import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 parameter an object with an own import * as fs from 'node:fs';const fs = require('node:fs');538 function is no longer supported
v18. 0. 0Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v17. 8. 0Melewati parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');15 dari suatu objek dengan fungsi import * as fs from 'node:fs';const fs = require('node:fs');538 sendiri tidak digunakan lagi
v16. 0. 0The error returned may be an import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }23 if more than one error is returned
v15. 2. 0, v14. 17. 0Argumen opsi mungkin menyertakan AbortSignal untuk membatalkan permintaan writeFile yang sedang berlangsung
v14. 12. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter will stringify an object with an explicit import * as fs from 'node:fs';const fs = require('node:fs');538 function
v14. 0. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter won't coerce unsupported input to strings anymore
v10. 10. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter can now be any import * as fs from 'node:fs';const fs = require('node:fs');056 or a import * as fs from 'node:fs';const fs = require('node:fs');057
v10. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_83 saat runtime
v7. 4. 0The import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 parameter can now be a import * as fs from 'node:fs';const fs = require('node:fs');059
v7. 0. 0Parameter import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });49 tidak lagi opsional. Tidak melewatinya akan mengeluarkan peringatan penghentian dengan id DEP0013
v5. 0. 0Parameter import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_81 dapat menjadi deskriptor file sekarang
v0. 1. 29Added in. v0. 1. 29
Ketika import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_81 adalah nama file, secara asinkron menulis data ke file, mengganti file jika sudah ada. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string or a buffer
When import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }81 is a file descriptor, the behavior is similar to calling import * as fs from 'node:fs';const fs = require('node:fs');528 directly (which is recommended). See the notes below on using a file descriptor
Opsi import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); console.log('can access'); } catch { console.error('cannot access'); }_7 diabaikan jika import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 adalah buffer
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }1Jika import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 adalah sebuah string, maka itu menentukan pengkodean
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }2It is unsafe to use import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 multiple times on the same file without waiting for the callback. For this scenario, is recommended
Similarly to import { unlink } from 'node:fs'; unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });const { unlink } = require('node:fs'); unlink('/tmp/hello', (err) => { if (err) throw err; console.log('successfully deleted /tmp/hello'); });81 - import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });45 is a convenience method that performs multiple import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });41 calls internally to write the buffer passed to it. For performance sensitive code consider using
It is possible to use an to cancel an import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76. Cancelation is "best effort", and some amount of data is likely still to be written
Membatalkan permintaan yang sedang berlangsung tidak membatalkan permintaan sistem operasi individu melainkan buffering internal import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });45 melakukan
Using import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 with file descriptorsWhen import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }81 is a file descriptor, the behavior is almost identical to directly calling import * as fs from 'node:fs';const fs = require('node:fs');528 like
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }3The difference from directly calling import * as fs from 'node:fs';const fs = require('node:fs');528 is that under some unusual conditions, import * as fs from 'node:fs';const fs = require('node:fs');528 might write only part of the buffer and need to be retried to write the remaining data, whereas import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 retries until the data is entirely written (or an error occurs)
The implications of this are a common source of confusion. In the file descriptor case, the file is not replaced. The data is not necessarily written to the beginning of the file, and the file's original data may remain before and/or after the newly written data
For example, if import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });76 is called twice in a row, first to write the string import * as fs from 'node:fs';const fs = require('node:fs');608, then to write the string import * as fs from 'node:fs';const fs = require('node:fs');609, the file would contain import * as fs from 'node:fs';const fs = require('node:fs');610, and might contain some of the file's original data (depending on the size of the original file, and the position of the file descriptor). If a file name had been used instead of a descriptor, the file would be guaranteed to contain only import * as fs from 'node:fs';const fs = require('node:fs');609
import * as fs from 'node:fs';const fs = require('node:fs');612
HistoryVersionChangesv18. 0. 0
Melewati panggilan balik yang tidak valid ke argumen import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });_49 sekarang melempar import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });50 alih-alih import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });51
v12. 9. 0Added in. v12. 9. 0
Write an array of import * as fs from 'node:fs';const fs = require('node:fs');166s to the file specified by import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64 using import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');45
import * as fs from 'node:fs';const fs = require('node:fs');31 is the offset from the beginning of the file where this data should be written. If import * as fs from 'node:fs';const fs = require('node:fs');169, the data will be written at the current position
The callback will be given three arguments. import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }46, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27, and import * as fs from 'node:fs';const fs = require('node:fs');74. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27 is how many bytes were written from import * as fs from 'node:fs';const fs = require('node:fs');74
If this method is ed, it returns a promise for an import * as fs from 'node:fs';const fs = require('node:fs');076 with import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');27 and import * as fs from 'node:fs';const fs = require('node:fs');74 properties
It is unsafe to use import * as fs from 'node:fs';const fs = require('node:fs');630 multiple times on the same file without waiting for the callback. For this scenario, use
Di Linux, penulisan posisi tidak berfungsi saat file dibuka dalam mode penambahan. The kernel ignores the position argument and always appends the data to the end of the file
Synchronous API
The synchronous APIs perform all operations synchronously, blocking the event loop until the operation completes or fails
import * as fs from 'node:fs';const fs = require('node:fs');632
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 11. 15Ditambahkan. v0. 11. 15
Synchronously tests a user's permissions for the file or directory specified by import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');47. The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 argument is an optional integer that specifies the accessibility checks to be performed. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 should be either the value import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');50 or a mask consisting of the bitwise OR of any of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');51, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');52, and import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');53 (e. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');54). Check for possible values of import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48
If any of the accessibility checks fail, an import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });10 will be thrown. Otherwise, the method will return import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }4import * as fs from 'node:fs';const fs = require('node:fs');647
HistoryVersionChangesv7. 0. 0
Objek import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 yang diteruskan tidak akan pernah dimodifikasi
v5. 0. 0Parameter import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }_81 dapat menjadi deskriptor file sekarang
v0. 6. 7Ditambahkan. v0. 6. 7
Synchronously append data to a file, creating the file if it does not yet exist. import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();8 can be a string or a
The import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 option only affects the newly created file. See for more details
Jika import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }_8 adalah sebuah string, maka itu menentukan pengkodean
import { open } from 'node:fs/promises'; let filehandle; try { filehandle = await open('thefile.txt', 'r'); } finally { await filehandle?.close(); }5import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat ditentukan sebagai deskriptor file numerik yang telah dibuka untuk ditambahkan (menggunakan import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');64 atau import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });93). Deskriptor file tidak akan ditutup secara otomatis
import * as fs from 'node:fs';const fs = require('node:fs');657
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 6. 7Ditambahkan. v0. 6. 7
For detailed information, see the documentation of the asynchronous version of this API.
Lihat dokumentasi POSIX import { open } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); }const { open } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const line of file.readLines()) { console.log(line); } })();_7 untuk detail lebih lanjut
import * as fs from 'node:fs';const fs = require('node:fs');663
HistoryVersionChangesv7. 6. 0
Parameter import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_47 dapat berupa objek WHATWG import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });53 menggunakan protokol import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });54
v0. 1. 97Ditambahkan. v0. 1. 97
Synchronously changes owner and group of a file. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6. This is the synchronous version of
Lihat dokumentasi POSIX import { open } from 'node:fs/promises'; let filehandle = null; try { filehandle = await open('temp.txt', 'r+'); await filehandle.truncate(4); } finally { await filehandle?.close(); }2 untuk detail lebih lanjut
import * as fs from 'node:fs';const fs = require('node:fs');670
Closes the file descriptor. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6
Calling import * as fs from 'node:fs';const fs = require('node:fs');672 on any file descriptor (import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();64) that is currently in use through any other import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });56 operation may lead to undefined behavior
Lihat dokumentasi POSIX import { open, } from 'node:fs/promises'; const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close();const { open, } = require('node:fs/promises'); (async () => { const file = await open('./some/file/to/read'); for await (const chunk of file.readableWebStream()) console.log(chunk); await file.close(); })();_66 untuk detail lebih lanjut
import * as fs from 'node:fs';const fs = require('node:fs');676
HistoryVersionChangesv14. 0. 0
Changed import * as fs from 'node:fs';const fs = require('node:fs');10 argument to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 and imposed stricter type validation
v8. 5. 0Ditambahkan. v8. 5. 0
Synchronously copies import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');72 to import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73. By default, import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');73 is overwritten if it already exists. Returns import { open } from 'node:fs/promises'; const fd = await open('sample.txt'); fd.createReadStream({ start: 90, end: 99 });6. Node. js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node. js will attempt to remove the destination
import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');48 adalah bilangan bulat opsional yang menentukan perilaku operasi penyalinan. It is possible to create a mask consisting of the bitwise OR of two or more values (e. g. import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_75)
import * as fs from 'node:fs';const fs = require('node:fs');689
HistoryVersionChangesv17. 6. 0, v16. 15. 0
Menerima opsi import { unlink } from 'node:fs/promises'; try { await unlink('/tmp/hello'); console.log('successfully deleted /tmp/hello'); } catch (error) { console.error('there was an error:', error.message); }const { unlink } = require('node:fs/promises'); (async function(path) { try { await unlink(path); console.log(`successfully deleted ${path}`); } catch (error) { console.error('there was an error:', error.message); } })('/tmp/hello');_86 tambahan untuk menentukan apakah akan melakukan resolusi jalur untuk symlink
v16. 7. 0Ditambahkan. v16. 7. 0