open[] thường tiêu tốn một lượng lớn bộ nhớ vì mỗi VU giữ một bản sao riêng của tệp trong bộ nhớ. Để giảm mức tiêu thụ bộ nhớ, chúng tôi thực sự khuyên bạn nên sử dụng SharedArray cho CSV, JSON và các tệp khác dành cho tham số hóa tập lệnh
Chức năng chỉ khả dụng trong "bối cảnh khởi tạo"
Đây là một hàm chỉ có thể được gọi từ ngữ cảnh init [còn gọi là mã khởi tạo], mã trong ngữ cảnh chung, bên ngoài hàm mặc định xuất chính {. }
Bằng cách giới hạn nó trong ngữ cảnh init, chúng tôi có thể dễ dàng xác định tệp cục bộ nào cần thiết để chạy thử nghiệm và do đó, chúng tôi cần gói gì khi phân phối thử nghiệm cho nhiều nút trong thử nghiệm phân cụm/phân tán
Xem thêm ví dụ trên trang này. Để có mô tả chi tiết hơn, hãy xem Running k6
Thay đổi lớn trong v0. 36. 0
kể từ k6 v0. 36. 0, các VU hiện chỉ bị hạn chế đối với các tệp open[] cũng được mở trong ngữ cảnh ban đầu của VU đầu tiên - tệp được khởi tạo để nhận các tùy chọn đã xuất từ tập lệnh JS [__VU==0]. Điều này có nghĩa là đoạn mã như if [__VU > 0] { const arr = open[". /arr. json"]; } sẽ dẫn đến lỗi
ParameterTypeDescriptionfilePathstringThe path to the file, absolute or relative, that will be read into memory. The file will only be loaded once, even when running with several VUs. modestringBy default, the contents of the file are read as text, but if you specify b, the file will be read as binary data instead
Returns
TypeDescriptionstring / ArrayBufferThe contents of the file, returned as string or ArrayBuffer [if b was specified as the mode]
Breaking change in v0. 32. 0
Since k6 v0. 32. 0 mở [. , 'b'] trả về một đối tượng ArrayBuffer thay vì một mảng số [byte]. Nếu bạn cần thao tác dữ liệu nhị phân, bạn sẽ cần bọc đối tượng ArrayBuffer trong chế độ xem mảng đã nhập
Mô-đun
4 cho phép tương tác với hệ thống tệp theo cách được mô hình hóa trên các chức năng POSIX tiêu chuẩnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để sử dụng các API dựa trên lời hứa
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Để sử dụng API gọi lại và đồng bộ hóa
import * as fs from 'node:fs';
const fs = require['node:fs'];
Tất cả các hoạt động của hệ thống tệp đều có biểu mẫu đồng bộ, gọi lại và dựa trên lời hứa và có thể truy cập bằng cả cú pháp CommonJS và Mô-đun ES6 [ESM]
Ví dụ hứa hẹn #
Các hoạt động dựa trên lời hứa trả về một lời hứa được thực hiện khi hoạt động không đồng bộ hoàn tất
import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ví dụ gọi lại #
Biểu mẫu gọi lại lấy hàm gọi lại hoàn thành làm đối số cuối cùng của nó và gọi hoạt động không đồng bộ. Các đối số được truyền cho lệnh gọi lại hoàn thành phụ thuộc vào phương thức, nhưng đối số đầu tiên luôn được dành riêng cho một ngoại lệ. Nếu thao tác hoàn tất thành công, thì đối số đầu tiên là
5 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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']; }];
Các phiên bản dựa trên gọi lại của API mô-đun
4 được ưu tiên sử dụng hơn so với việc sử dụng các API hứa hẹn khi hiệu suất tối đa [cả về thời gian thực hiện và cấp phát bộ nhớ] là bắt buộcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Ví dụ đồng bộ#
Các API đồng bộ chặn Nút. js và thực thi JavaScript tiếp theo cho đến khi thao tác hoàn tất. Các ngoại lệ được đưa ra ngay lập tức và có thể được xử lý bằng cách sử dụng
8 hoặc có thể được phép nổi lênimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
API hứa hẹn #
Lịch sửPhiên bảnChangesv14. 0. 0
tiếp xúc như
9v11. 14. 0, v10. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
API này không còn thử nghiệm nữa
v10. 1. 0API chỉ có thể truy cập qua
00v10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
API
01 cung cấp các phương thức hệ thống tệp không đồng bộ trả về lời hứaimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The promise APIs use the underlying Node. js threadpool to perform file system operations off the event loop thread. 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.
02#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
A object is an object wrapper for a numeric file descriptor
Instances of the object are created by the
03 methodimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
All objects are s
If a is not closed using the
04 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 futureEvent.import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
05#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
05 event is emitted when the has been closed and can no longer be usedimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
07#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
HistoryVersionChangesv15. 14. 0, v14. 18. 0
The
08 argument supportsimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter won't coerce unsupported input to strings anymorev10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Alias of
03import * as fs from 'node:fs';
const fs = require['node:fs'];
When operating on file handles, the mode cannot be changed from what it was set to with
03. Therefore, this is equivalent toimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
03import * as fs from 'node:fs';
const fs = require['node:fs'];
06#import * as fs from 'node:fs';
const fs = require['node:fs'];
Modifies the permissions on the file. See
07import * as fs from 'node:fs';
const fs = require['node:fs'];
08#import * as fs from 'node:fs';
const fs = require['node:fs'];
09 The file's new owner's user idimport * as fs from 'node:fs';
const fs = require['node:fs'];
00 The file's new group's group idimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Changes the ownership of the file. A wrapper for
02import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Closes the file handle after waiting for any pending operation on the handle to complete
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'];
05#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Unlike the 16 KiB default
06 for a , the stream returned by this method has a defaultimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 of 64 KiBimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 can includeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
09 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 values to read a range of bytes from the file instead of the entire file. Bothimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 are inclusive and start counting at 0, allowed values are in the [0,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
13] range. Ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 is omitted orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
16 reads sequentially from the current file position. Theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 can be any one of those accepted byimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
If the
02 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 naturallyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
By default, the stream will emit a
05 event after it has been destroyed. Set theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 option toimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 to change this behaviorimport * as fs from 'node:fs';
const fs = require['node:fs'];
If
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. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 is set to true [default behavior], onimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 orimport * as fs from 'node:fs';
const fs = require['node:fs'];
05 the file descriptor will be closed automaticallyimport * as fs from 'node:fs';
const fs = require['node:fs'];
Một ví dụ để đọc 10 byte cuối cùng của tệp dài 100 byte
import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
06#import * as fs from 'node:fs';
const fs = require['node:fs'];
08 may also include aimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
09 option to allow writing data at some position past the beginning of the file, allowed values are in the [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'];
13] range. Sửa đổi một tệp thay vì thay thế nó có thể yêu cầu tùy chọnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10import * as fs from 'node:fs';
const fs = require['node:fs'];
11 được đặt thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
12 thay vì mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
13.import * as fs from 'node:fs';
const fs = require['node:fs'];
17 có thể là bất kỳ một trong số đó được chấp nhận bởiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Nếu
02 được đặt thành true [hành vi mặc định] trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
17, bộ mô tả tệp sẽ tự động bị đóng. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
By default, the stream will emit a
05 event after it has been destroyed. Set theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 option toimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 to change this behaviorimport * as fs from 'node:fs';
const fs = require['node:fs'];
22#import * as fs from 'node:fs';
const fs = require['node:fs'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Buộc tất cả các hoạt động I/O được xếp hàng hiện tại được liên kết với tệp về trạng thái hoàn thành I/O được đồng bộ hóa của hệ điều hành. Tham khảo tài liệu POSIX
24 để biết chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Không giống như
25, phương pháp này không xóa siêu dữ liệu đã sửa đổiimport * as fs from 'node:fs';
const fs = require['node:fs'];
26#import * as fs from 'node:fs';
const fs = require['node:fs'];
27#import * as fs from 'node:fs';
const fs = require['node:fs'];
28. . Một bộ đệm sẽ chứa đầy dữ liệu tệp đã đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí trong bộ đệm để bắt đầu điềnimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
31. Vị trí bắt đầu đọc dữ liệu từ tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí sẽ được cập nhật. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 là số nguyên, vị trí tệp hiện tại sẽ không thay đổiimport * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
34#import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v13. 11. 0, v12. 17. 0
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28. . A buffer that will be filled with the file data read. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
37import * as fs from 'node:fs';
const fs = require['node:fs'];
29 The location in the buffer at which to start filling. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
30 The number of bytes to read. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31 . The location where to begin reading data from the file. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí sẽ được cập nhật. Ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 is an integer, the current file position will remain unchanged. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
46#import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v18. 2. 0, v16. 17. 0
28. . Một bộ đệm sẽ chứa đầy dữ liệu tệp đã đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
29 The location in the buffer at which to start filling. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
30 The number of bytes to read. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31 The location where to begin reading data from the file. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, data will be read from the current file position, and the position will be updated. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 là số nguyên, vị trí tệp hiện tại sẽ không thay đổi. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
57#import * as fs from 'node:fs';
const fs = require['node:fs'];
Returns a
58 that may be used to read the files dataimport * as fs from 'node:fs';
const fs = require['node:fs'];
An error will be thrown if this method is called more than once or is called after the
02 is closed or closingimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
While the
58 will read the file to completion, it will not close theimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 automatically. User code must still call theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
62 methodimport * as fs from 'node:fs';
const fs = require['node:fs'];
63#import * as fs from 'node:fs';
const fs = require['node:fs'];
08 .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns. Fulfills upon a successful read with the contents of the file. If no encoding is specified [using
65], the data is returned as a object. Otherwise, the data will be a stringimport * as fs from 'node:fs';
const fs = require['node:fs'];
Asynchronously reads the entire contents of a file
If
08 is a string, then it specifies theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The has to support reading
If one or more
68 calls are made on a file handle and then aimport * as fs from 'node:fs';
const fs = require['node:fs'];
69 call is made, the data will be read from the current position till the end of the file. It doesn't always read from the beginning of the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
70#import * as fs from 'node:fs';
const fs = require['node:fs'];
Convenience method to create a
71 interface and stream over the file. Seeimport * as fs from 'node:fs';
const fs = require['node:fs'];
16 for the optionsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
0import * as fs from 'node:fs';
const fs = require['node:fs'];
73#import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v13. 13. 0, v12. 17. 0
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. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 is not aimport * as fs from 'node:fs';
const fs = require['node:fs'];
77, the data will be read from the current position. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Fulfills upon success an object containing two properties
Read from a file and write to an array of s
79#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 5. 0
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
81#import * as fs from 'node:fs';
const fs = require['node:fs'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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
83 documentation for more detailimport * as fs from 'node:fs';
const fs = require['node:fs'];
84#import * as fs from 'node:fs';
const fs = require['node:fs'];
Truncates the file
If the file was larger than
85 bytes, only the firstimport * as fs from 'node:fs';
const fs = require['node:fs'];
85 bytes will be retained in the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
The following example retains only the first four bytes of the file
0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If the file previously was shorter than
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]import * as fs from 'node:fs';
const fs = require['node:fs'];
If
85 is negative thenimport * as fs from 'node:fs';
const fs = require['node:fs'];
39 will be usedimport * as fs from 'node:fs';
const fs = require['node:fs'];
91#import * as fs from 'node:fs';
const fs = require['node:fs'];
Change the file system timestamps of the object referenced by the then resolves the promise with no arguments upon success
92#import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv14. 0. 0
The
28 parameter won't coerce unsupported input to buffers anymorev10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v10. 0. 0
28 . .import * as fs from 'node:fs';
const fs = require['node:fs'];
29 The start position from withinimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 where the data to write beginsimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 The number of bytes fromimport * 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'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31 . The offset from the beginning of the file where the data fromimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 should be written. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 is not aimport * as fs from 'node:fs';
const fs = require['node:fs'];
77, the data will be written at the current position. See the POSIXimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 documentation for more detail. 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'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Returns.
Write
28 to the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
The promise is resolved with an object containing two properties
It is unsafe to use
07 multiple times on the same file without waiting for the promise to be resolved [or rejected]. For this scenario, useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
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
09#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v18. 3. 0, v16. 17. 0
Write
28 to the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
Similar to the above
11 function, this version takes an optionalimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object is specified, it will default with the above valuesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
14#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
The
15 parameter won't coerce unsupported input to strings anymorev10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
15import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 . The offset from the beginning of the file where the data fromimport * as fs from 'node:fs';
const fs = require['node:fs'];
15 should be written. Ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 is not aimport * as fs from 'node:fs';
const fs = require['node:fs'];
77 the data will be written at the current position. See the POSIXimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 documentation for more detail. 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'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 The expected string encoding. Default.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns.
Write
15 to the file. Ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 errorimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The promise is resolved with an object containing two properties
27 the number of bytes writtenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28 một tham chiếu đếnimport * as fs from 'node:fs';
const fs = require['node:fs'];
15 bằng văn bảnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
It is unsafe to use
07 multiple times on the same file without waiting for the promise to be resolved [or rejected]. For this scenario, useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
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
32#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv15. 14. 0, v14. 18. 0
The
08 argument supportsimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter won't coerce unsupported input to strings anymorev10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Ghi dữ liệu vào tệp không đồng bộ, thay thế tệp nếu tệp đã tồn tại.
08 có thể là một chuỗi, một bộ đệm, một hoặc một đối tượng. Lời hứa được giải quyết mà không có tranh luận khi thành côngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If
08 is a string, then it specifies theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Phải hỗ trợ viết
Sẽ không an toàn khi sử dụng
03 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyết [hoặc bị từ chối]import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu một hoặc nhiều lệnh gọi
07 được thực hiện trên một bộ xử lý tệp và sau đó một lệnh gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 được thực hiện, dữ liệu sẽ được ghi từ vị trí hiện tại cho đến hết tệp. It doesn't always write from the beginning of the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
44#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Write an array of s to the file
The promise is resolved with an object containing a two properties
It is unsafe to call
45 multiple times on the same file without waiting for the promise to be resolved [or rejected]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
On Linux, positional writes don't 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
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'];
Tests a user's permissions for the file or directory specified by
47. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 valueimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 File access constants for possible values ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
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
56 can be read and written by the current processimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Using
57 to check for the accessibility of a file before callingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 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 accessibleimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
59#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Asynchronously append data to a file, creating the file if it does not yet exist.
08 can be a string or aimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If
08 is a string, then it specifies theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 may be specified as a that has been opened for appending [usingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03]import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
67#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Changes the permissions of a file
68#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Changes the ownership of a file
69#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
Changed
10 argument toimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 and imposed stricter type validationv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
72 . . source filename to copyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 operationimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
77. The copy operation will fail ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 existsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is usedimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Sao chép không đồng bộ
72 sangimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 existsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
No guarantees are made about the atomicity of the copy operation. Nếu xảy ra lỗi sau khi tệp đích đã được mở để ghi, một nỗ lực sẽ được thực hiện để xóa đích
85#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv17. 6. 0, v16. 15. 0
Accepts an additional
86 option to specify whether to perform path resolution for symlinksv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v16. 7. 0
72 . source path to copyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 path to copy toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 dereference symlinks. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 isimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01, and the destination exists, throw an error. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Function to filter copied files/directories. Returnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 to ignore it. Can also return aimport * as fs from 'node:fs';
const fs = require['node:fs'];
99 that resolves toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 overwrite existing file or directory. The copy operation will ignore errors if you set this to false and the destination exists. Use theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. 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'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Whenimport { 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 timestamps fromimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 will be preserved. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 copy directories recursively Default.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']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, path resolution for symlinks will be skipped. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Asynchronously copies the entire directory structure from
72 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 filesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
When copying a directory to another directory, globs are not supported and behavior is similar to
18import { 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#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']; }];
Deprecated since. v10. 0. 0
Changes the permissions on a symbolic link
This method is only implemented on macOS
20#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']; }];
HistoryVersionChangesv10. 6. 0
This API is no longer deprecated
v10. 0. 0Đã thêm vào. v10. 0. 0
Changes the ownership on a symbolic link
21import { 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']; }];
Added in. v14. 5. 0, v12. 19. 0
Changes the access and modification times of a file in the same way as
22, with the difference that if the path refers to a symbolic link, then the link is not dereferenced. instead, the timestamps of the symbolic link itself are changedimport { 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#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']; }];
Creates a new link from the
24 to theimport { 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 POSIXimport { 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 detailimport { 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#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']; }];
HistoryVersionChangesv10. 5. 0
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
Equivalent to
29 unlessimport { 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']; }];
47 refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. Refer to the POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 document for more detailimport { 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#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']; }];
Asynchronously creates a directory
Đối số
08 tùy chọn có thể là một số nguyên chỉ địnhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 [các bit quyền và dính] hoặc một đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 và thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 cho biết có nên tạo thư mục mẹ hay không. Gọiimport { 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 khiimport { 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']; }];
47 là một thư mục tồn tại dẫn đến từ chối chỉ khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 là saiimport { 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']; }];
0import * as fs from 'node:fs';
const fs = require['node:fs'];
40#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']; }];
Lịch sửPhiên bảnThay đổiv16. 5. 0, v14. 18. 0
Tham số
41 hiện chấp nhận một chuỗi rỗngv10. 0. 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']; }];
Đã thêm vào. v10. 0. 0
Tạo một thư mục tạm thời duy nhất. Một tên thư mục duy nhất được tạo bằng cách thêm sáu ký tự ngẫu nhiên vào cuối
41 được cung cấp. Do sự không nhất quán của nền tảng, hãy tránh sử dụng các ký tự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 trongimport { 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. Một số nền tảng, đặc biệt là BSD, có thể trả về nhiều hơn sáu ký tự ngẫu nhiên và thay thế các ký tự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 ở cuối trongimport { 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 bằng các ký tự ngẫu nhiênimport { 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']; }];
Đối số
08 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 chỉ định mã hóa ký tự sẽ sử dụngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
1import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 method will append the six randomly selected characters directly to theimport { 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 string. Ví dụ: được cung cấp một thư mụcimport { 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, nếu mục đích là tạo một thư mục tạm thời trongimport { 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, thì ____641 phải kết thúc bằng dấu phân cách đường dẫn dành riêng cho nền tảng [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#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']; }];
HistoryVersionChangesv11. 1. 0
The
10 argument is now optional and defaults toimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v10. 0. 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']; }];
Đã thêm vào. v10. 0. 0
Opens a
Refer to the POSIX
58 documentation for more detailimport { 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']; }];
Some characters [
59] are reserved under Windows as documented by Naming Files, Paths, and Namespaces. Under NTFS, if the filename contains a colon, Node. js will open a file system stream, as described by this MSDN pageimport { 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#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']; }];
HistoryVersionChangesv13. 1. 0, v12. 16. 0
The
61 option was introducedv12. 12. 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']; }];
Added in. v12. 12. 0
Asynchronously open a directory for iterative scanning. See the POSIX
62 documentation for more detailimport { 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']; }];
Creates an , which contains all further functions for reading from and cleaning up the directory
The
17 option sets the encoding for theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 while opening the directory and subsequent read operationsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Example using async iteration
2import * as fs from 'node:fs';
const fs = require['node:fs'];
When using the async iterator, the object will be automatically closed after the iterator exits
65#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']; }];
HistoryVersionChangesv10. 11. 0
New option
66 was addedv10. 0. 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']; }];
Đã thêm vào. v10. 0. 0
Reads the contents of a directory
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the filenames. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the filenames returned will be passed as objectsimport { 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']; }];
If
71 is set toimport { 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, the resolved array will contain objectsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
3import * as fs from 'node:fs';
const fs = require['node:fs'];
73#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']; }];
HistoryVersionChangesv15. 2. 0, v14. 17. 0
The options argument may include an AbortSignal to abort an ongoing readFile request
v10. 0. 0Đã thêm vào. v10. 0. 0
Asynchronously reads the entire contents of a file
If no encoding is specified [using
65], the data is returned as a object. Otherwise, the data will be a stringimport * as fs from 'node:fs';
const fs = require['node:fs'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
When the
47 is a directory, the behavior ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 is platform-specific. On macOS, Linux, and Windows, the promise will be rejected with an error. On FreeBSD, a representation of the directory's contents will be returnedimport { 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']; }];
An example of reading a
78 file located in the same directory of the running codeimport { 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']; }];
4import * as fs from 'node:fs';
const fs = require['node:fs'];
It is possible to abort an ongoing
79 using an . If a request is aborted the promise returned is rejected with animport { 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']; }];
80import { 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']; }];
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
81 performsimport { 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']; }];
Any specified has to support reading
82#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']; }];
Reads the contents of the symbolic link referred to by
47. See the POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
84 documentation for more detail. The promise is resolved with theimport { 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 upon successimport { 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']; }];
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the link path returned. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the link path returned will be passed as a objectimport { 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#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']; }];
Determines the actual location of
47 using the same semantics as theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 functionimport { 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']; }];
Only paths that can be converted to UTF8 strings are supported
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the path. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the path returned will be passed as a objectimport { 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']; }];
On Linux, when Node. js is linked against musl libc, the procfs file system must be mounted on
97 in order for this function to work. Glibc does not have this restrictionimport { 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#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']; }];
Renames
99 toimport { 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']; }];
25import { 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']; }];
501#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv16. 0. 0
Sử dụng
502 trên một tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 trên POSIXv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Việc sử dụng
502 trên mộtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 không tồn tại sẽ không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504v16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10 option is deprecated, using it triggers a deprecation warningv14. 14. 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']; }];
The
10 option is deprecated, useimport { 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']; }];
511 insteadv13. 3. 0, v12. 16. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
512 option is renamed toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513, and its default is 0. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 option has been removed, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515 errors use the same retry logic as other errors. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 option is now supported.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517 errors are now retriedv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10,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']; }];
512, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 options are now supportedv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
47 . .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js retries the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive directory removal. In recursive mode, operations are retried on failure. 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'];
01. Deprecatedimport * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Removes the directory identified by
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Using
542 on a file [not a directory] results in the promise being rejected with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504 error on Windows and animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 error on POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
To get a behavior similar to the
545 Unix command, useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
546 with optionsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
547import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
548#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, exceptions will be ignored ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 does not exist. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js will retry the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive directory removal. In recursive mode operations are retried on failure. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Returns. Fulfills with
6 upon successimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Removes files and directories [modeled on the standard POSIX
573 utility]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
574#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv10. 5. 0
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
576#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv19. 0. 0
If the
577 argument isimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
5 or omitted, Node. js will autodetectimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
579 type and automatically selectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
580 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
581v10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
Creates a symbolic link
The
577 argument is only used on Windows platforms and can be one ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
583,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
585. If theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
577 argument is not a string, Node. js will autodetectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 type and useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
583. If theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 does not exist,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584 will be used. Các điểm giao nhau của Windows yêu cầu đường dẫn đích phải tuyệt đối. Khi sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
585, đối 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'];
579 sẽ tự động được chuẩn hóa thành đường dẫn tuyệt đốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
594import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Truncates [shortens or extends the length] of the content at
47 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 bytesimport * as fs from 'node:fs';
const fs = require['node:fs'];
597#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If
47 refers to a symbolic link, then the link is removed without affecting the file or directory to which that link refers. If theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 file path that is not a symbolic link, the file is deleted. See the POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
00 documentation for more detailimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
01import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Change the file system timestamps of the object referenced by
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
03 andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04 arguments follow these rulesimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Values can be either numbers representing Unix epoch time,
05s, or a numeric string likeimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
06import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- If the value can not be converted to a number, or is
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08, orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09, animport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 will be thrownimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
11#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v15. 9. 0, v14. 18. 0
12 . .import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
14 Indicates whether the process should continue to run as long as files are being watched. Default.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 Indicates whether all subdirectories should be watched, or only the current directory. This applies when a directory is specified, and only on supported platforms [See caveats]. Default.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']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
17 Specifies the character encoding to be used for the filename passed to the listener. Default.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
20 An used to signal when the watcher should stopimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Returns. of objects with the properties
Returns an async iterator that watches for changes on
12, whereimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
12 is either a file or a directoryimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
5import * as fs from 'node:fs';
const fs = require['node:fs'];
On most platforms,
23 is emitted whenever a filename appears or disappears in the directoryimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
All the caveats for
24 also apply toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
25import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
26#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv15. 14. 0, v14. 18. 0
The
08 argument supportsimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 2. 0, v14. 17. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The options argument may include an AbortSignal to abort an ongoing writeFile request
v14. 0. 0The
08 parameter won't coerce unsupported input to strings anymorev10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Asynchronously writes data to a file, replacing the file if it already exists.
08 can be a string, a buffer, an , or an objectimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
17 option is ignored ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 is a bufferimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Any specified has to support writing
It is unsafe to use
38 multiple times on the same file without waiting for the promise to be settledimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Similarly to
39 -import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
40 is a convenience method that performs multipleimport { 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 usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
42 orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
It is possible to use an to cancel an
38. Cancelation is "best effort", and some amount of data is likely still to be writtenimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
45 performsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
46#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v18. 4. 0, v16. 17. 0
Returns an object containing commonly used constants for file system operations. The object is the same as
47. See FS constants for more detailsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Callback API#
The callback APIs perform all operations asynchronously, without blocking the event loop, then invoke a callback function upon completion or error
The callback APIs use the underlying Node. js threadpool to perform file system operations off the event loop thread. 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
48#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv6. 3. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The constants like
55, etc which were present directly onimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 were moved intoimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 as a soft deprecation. Thus for Node. jsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
58 useimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 to access those constants, or do something likeimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
60 to work with all versionsv0. 11. 15import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 11. 15
Tests a user's permissions for the file or directory specified by
47. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 valueimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 File access constants for possible values ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The final argument,
49, is a callback function that is invoked with a possible error argument. If any of the accessibility checks fail, the error argument will be animport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 object. The following examples check ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
78 exists, and if it is readable or writableimport { 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']; }];
Do not use
73 to check for the accessibility of a file before callingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
76. 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 accessibleimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
write [NOT RECOMMENDED]
6import * as fs from 'node:fs';
const fs = require['node:fs'];
write [RECOMMENDED]
7import * as fs from 'node:fs';
const fs = require['node:fs'];
read [NOT RECOMMENDED]
8import * as fs from 'node:fs';
const fs = require['node:fs'];
read [RECOMMENDED]
9import * as fs from 'node:fs';
const fs = require['node:fs'];
The "not recommended" examples above check for accessibility and then use the file; the "recommended" examples are better because they use the file directly and handle the error, if any
Nói chung, chỉ kiểm tra khả năng truy cập của tệp nếu tệp đó sẽ không được sử dụng trực tiếp, ví dụ khi khả năng truy cập tệp là tín hiệu từ một quy trình khác
On Windows, access-control policies [ACLs] on a directory may limit access to a file or directory. The
73 function, however, does not check the ACL and therefore may report that a path is accessible even if the ACL restricts the user from reading or writing to itimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
78#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The passed
08 object will never be modifiedv5. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
581 parameter can be a file descriptor nowv0. 6. 7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 6. 7
Asynchronously append data to a file, creating the file if it does not yet exist.
08 can be a string or aimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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'];
The
47 may be specified as a numeric file descriptor that has been opened for appending [usingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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]. The file descriptor will not be closed automaticallyimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
2import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
94#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 30import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 30
Asynchronously changes the permissions of a file. No arguments other than a possible exception are given to the completion callback
See the POSIX
07 documentation for more detailimport * as fs from 'node:fs';
const fs = require['node:fs'];
3File modes#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
48 argument used in both theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
006 andimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
007 methods is a numeric bitmask created using a logical OR of the following constantsConstantOctalDescriptionimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
008import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
009read by ownerimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
010import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
011write by ownerimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
012import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
013execute/search by ownerimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
014import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
015read by groupimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
016import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
017write by groupimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
018import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
019execute/search by groupimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
020import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
021read by othersimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
022import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
023write by othersimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
024import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
025execute/search by othersimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
An easier method of constructing the
48 is to use a sequence of three octal digits [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'];
027]. The left-most digit [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
028 in the example], specifies the permissions for the file owner. The middle digit [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
029 in the example], specifies permissions for the group. The right-most digit [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
030 in the example], specifies the permissions for othersNumberDescriptionimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
028read, write, and executeimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
029read and writeimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
030read and executeimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
034read onlyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
035write and executeimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
036write onlyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
037execute onlyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
39no permissionimport * as fs from 'node:fs';
const fs = require['node:fs'];
For example, the octal value
039 meansimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
- The owner may read, write, and execute the file
- The group may read and write the file
- Others may read and execute the file
When using raw numbers where file modes are expected, any value larger than
040 may result in platform-specific behaviors that are not supported to work consistently. Therefore constants likeimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
041,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
042, orimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
043 are not exposed inimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
47import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Caveats. on Windows only the write permission can be changed, and the distinction among the permissions of group, owner, or others is not implemented
045#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 97import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 97
Asynchronously changes owner and group of a file. No arguments other than a possible exception are given to the completion callback
See the POSIX
02 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
056#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v15. 9. 0, v14. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
A default callback is now used if one is not provided
v10. 0. 0The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Closes the file descriptor. No arguments other than a possible exception are given to the completion callback
Calling
063 on any file descriptor [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
064] that is currently in use through any otherimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
56 operation may lead to undefined behaviorimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
066 documentation for more detailimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
067#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v14. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Changed
10 argument toimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 and imposed stricter type validationv8. 5. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v8. 5. 0
Asynchronously copies
72 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 arguments other than a possible exception are given to the callback function. 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 destinationimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 is an optional integer that specifies 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]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 existsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is usedimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
082#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v17. 6. 0, v16. 15. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Accepts an additional
86 option to specify whether to perform path resolution for symlinksv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v16. 7. 0
72 . source path to copyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 path to copy toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 dereference symlinks. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 isimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01, and the destination exists, throw an error. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Function to filter copied files/directories. Returnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 to ignore it. Can also return aimport * as fs from 'node:fs';
const fs = require['node:fs'];
99 that resolves toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 overwrite existing file or directory. The copy operation will ignore errors if you set this to false and the destination exists. Use theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. 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'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Whenimport { 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 timestamps fromimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 will be preserved. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 copy directories recursively Default.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']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, path resolution for symlinks will be skipped. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Asynchronously copies the entire directory structure from
72 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 filesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
When copying a directory to another directory, globs are not supported and behavior is similar to
18import { 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']; }];
019#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv16. 10. 0
The
56 option does not needimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
11 method if animport * as fs from 'node:fs';
const fs = require['node:fs'];
064 was providedv16. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
56 option does not needimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
024 method ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 isimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
064 option accepts FileHandle argumentsv14. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Change
00 default toimport * as fs from 'node:fs';
const fs = require['node:fs'];
97v13. 6. 0, v12. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
56 options allow overriding the usedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 implementationv12. 10. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Enable
00 optionv11. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Impose new restrictions on
09 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10, throwing more appropriate errors in cases when we cannot reasonably handle the input valuesv7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The passed
08 object will never be modifiedv2. 3. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The passed
08 object can be a string nowv0. 1. 31import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 31
Unlike the 16 KiB default
06 for a , the stream returned by this method has a defaultimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 of 64 KiBimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 can includeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
09 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 values to read a range of bytes from the file instead of the entire file. Bothimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 are inclusive and start counting at 0, allowed values are in the [0,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
13] range. Ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
064 is specified andimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09 is omitted orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
051 reads sequentially from the current file position. Theimport * as fs from 'node:fs';
const fs = require['node:fs'];
17 can be any one of those accepted byimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
If
064 is specified,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
054 will ignore theimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 argument and will use the specified file descriptor. This means that noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
056 event will be emitted.import * as fs from 'node:fs';
const fs = require['node:fs'];
064 should be blocking; non-blockingimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
064s should be passed toimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If
064 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 naturallyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
By default, the stream will emit a
05 event after it has been destroyed. Set theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 option toimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 to change this behaviorimport * as fs from 'node:fs';
const fs = require['node:fs'];
By providing the
56 option, it is possible to override the correspondingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 implementations forimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
11,import * as fs from 'node:fs';
const fs = require['node:fs'];
066, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
024. When providing theimport * as fs from 'node:fs';
const fs = require['node:fs'];
56 option, an override forimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
066 is required. If noimport * as fs from 'node:fs';
const fs = require['node:fs'];
064 is provided, an override forimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
11 is also required. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 isimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, an override forimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
024 is also requiredimport * as fs from 'node:fs';
const fs = require['node:fs'];
If
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. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 is set to true [default behavior], onimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 orimport * as fs from 'node:fs';
const fs = require['node:fs'];
05 the file descriptor will be closed automaticallyimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 đặt chế độ tệp [quyền và bit dính], nhưng chỉ khi tệp được tạoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một ví dụ để đọc 10 byte cuối cùng của tệp dài 100 byte
4import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
081#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv16. 10. 0
The
56 option does not needimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
11 method if animport * as fs from 'node:fs';
const fs = require['node:fs'];
064 was providedv16. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
56 option does not needimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
024 method ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 isimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
064 option accepts FileHandle argumentsv14. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Change
00 default toimport * as fs from 'node:fs';
const fs = require['node:fs'];
97v13. 6. 0, v12. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
56 options allow overriding the usedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 implementationv12. 10. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Enable
00 optionv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The passed
08 object will never be modifiedv5. 5. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
02 option is supported nowv2. 3. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The passed
08 object can be a string nowv0. 1. 31import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 31
08 may also include aimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
09 option to allow writing data at some position past the beginning of the file, allowed values are in the [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'];
13] range. Modifying a file rather than replacing it may require theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 option to be set toimport * as fs from 'node:fs';
const fs = require['node:fs'];
12 rather than the defaultimport * as fs from 'node:fs';
const fs = require['node:fs'];
006. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 can be any one of those accepted byimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Nếu
02 được đặt thành true [hành vi mặc định] trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
17, bộ mô tả tệp sẽ tự động bị đóng. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
By default, the stream will emit a
05 event after it has been destroyed. Set theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 option toimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 to change this behaviorimport * as fs from 'node:fs';
const fs = require['node:fs'];
By providing the
56 option it is possible to override the correspondingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
56 implementations forimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
11,import * as fs from 'node:fs';
const fs = require['node:fs'];
41,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
019, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
024. Overridingimport * as fs from 'node:fs';
const fs = require['node:fs'];
021 withoutimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 can reduce performance as some optimizations [import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
023] will be disabled. When providing theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 option, overrides for at least one ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
41 andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
019 are required. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 option is supplied, an override forimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
11 is also required. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 isimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, an override forimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
024 is also requiredimport * as fs from 'node:fs';
const fs = require['node:fs'];
Like , if
064 is specified, will ignore theimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
47 argument and will use the specified file descriptor. This means that noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
056 event will be emitted.import * as fs from 'node:fs';
const fs = require['node:fs'];
064 should be blocking; non-blockingimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
064s should be passed toimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
038#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv1. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Deprecated since. v1. 0. 0
v0. 0. 2Added in. v0. 0. 2
Test whether or not the given path exists by checking with the file system. Then call the
49 argument with either true or falseimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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'];
The parameters for this callback are not consistent with other Node. js callbacks. Normally, the first parameter to a Node. js callback is an
046 parameter, optionally followed by other parameters. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
047 callback has only one boolean parameter. This is one reasonimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 recommended instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
047import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Using
047 to check for the existence of a file before callingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, orimport { 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 existimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
write [NOT RECOMMENDED]
6import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
write [RECOMMENDED]
7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
read [NOT RECOMMENDED]
8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
read [RECOMMENDED]
9import * as fs from 'node:fs';
const fs = require['node:fs'];
The "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
054#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 4. 7import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. 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
061 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
062#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 4. 7import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. 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
069 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
070#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 96import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added 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
24 documentation for details. No arguments other than a possible exception are given to the completion callbackimport * as fs from 'node:fs';
const fs = require['node:fs'];
078#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 95import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 95
Invokes the callback with the for the file descriptor
See the POSIX
086 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 96import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added 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
83 documentation for more detail. No arguments other than a possible exception are given to the completion callbackimport * as fs from 'node:fs';
const fs = require['node:fs'];
095import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 8. 6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 8. 6
Truncates the file descriptor. No arguments other than a possible exception are given to the completion callback
See the POSIX
102 documentation for more detailimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
If the file referred to by the file descriptor was larger than
85 bytes, only the firstimport * as fs from 'node:fs';
const fs = require['node:fs'];
85 bytes will be retained in the fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
For example, the following program retains only the first four bytes of the file
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']; }];
If the file previously was shorter than
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]import * as fs from 'node:fs';
const fs = require['node:fs'];
If
85 is negative thenimport * as fs from 'node:fs';
const fs = require['node:fs'];
39 will be usedimport * as fs from 'node:fs';
const fs = require['node:fs'];
109import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v4. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Numeric strings,
07, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 are now allowed time specifiersv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 4. 2
Change the file system timestamps of the object referenced by the supplied file descriptor. See
118import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
119#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The error returned may be an
123 if more than one error is returnedv10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 4. 7import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Deprecated since. v0. 4. 7
Changes the permissions on a symbolic link. No arguments other than a possible exception are given to the completion callback
This method is only implemented on macOS
See the POSIX
127 documentation for more detailimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
128#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
This API is no longer deprecated
v10. 0. 0The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 4. 7import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Documentation-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
135 documentation for more detailimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
136import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v14. 5. 0, v12. 19. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v14. 5. 0, v12. 19. 0
Changes the access and modification times of a file in the same way as
118, with the difference that if the path refers to a symbolic link, then the link is not dereferenced. instead, the timestamps of the symbolic link itself are changedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
No arguments other than a possible exception are given to the completion callback
141#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các tham số
24 và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 có thể là các đối tượng WHATWGimport { 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']; }];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Tạo một liên kết mới từ
24 đếnimport { 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. Xem tài liệu POSIXimport { 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 để biết thêm chi tiết. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport { 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']; }];
155#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 30import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 30
Truy xuất liên kết tượng trưng được tham chiếu bởi đường dẫn. Cuộc gọi lại nhận được hai đối số
166 trong đóimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
167 là một đối tượng.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
168 giống hệt vớiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
169, ngoại trừ việc nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 là một liên kết tượng trưng, thì chính liên kết đó đã được thống kê, không phải tệp mà nó đề cập đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
31 để biết thêm chi tiếtimport { 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']; }];
172#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v13. 11. 0, v12. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Ở chế độ
10, cuộc gọi lại hiện nhận đường dẫn được tạo đầu tiên làm đối sốv10. 12. 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']; }];
Đối số thứ hai bây giờ có thể là một đối tượng
08 với các thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 và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']; }];
48v10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 8import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 8
Asynchronously creates a directory
Cuộc gọi lại được đưa ra một ngoại lệ có thể xảy ra và, nếu
10 là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, đường dẫn thư mục đầu tiên được tạ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'];
188.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 vẫn có thể làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6 khiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 là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, nếu không có thư mục nào được tạoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số
08 tùy chọn có thể là một số nguyên chỉ địnhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 [các bit quyền và dính] hoặc một đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 và thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 cho biết có nên tạo thư mục mẹ hay không. Gọiimport { 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']; }];
197 khiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 là một thư mục tồn tại chỉ dẫn đến lỗi khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 saiimport { 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']; }];
On Windows, using
197 on the root directory even with recursion will result in an errorimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
001 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
002#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v16. 5. 0, v14. 18. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Tham số
41 hiện chấp nhận một chuỗi rỗngv10. 0. 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']; }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v6. 2. 1import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is optional nowv5. 10. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v5. 10. 0
Creates a unique temporary directory
Generates six random characters to be appended behind a required
41 to create a unique temporary directory. Due to platform inconsistencies, avoid trailingimport { 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 characters inimport { 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. Some platforms, notably the BSDs, can return more than six random characters, and replace trailingimport { 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 characters inimport { 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 with random charactersimport { 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']; }];
The created directory path is passed as a string to the callback's second parameter
Đối số
08 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 chỉ định mã hóa ký tự sẽ sử dụngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
018 method will append the six randomly selected characters directly to theimport * as fs from 'node:fs';
const fs = require['node:fs'];
41 string. For instance, given a directoryimport { 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, if the intention is to create a temporary directory withinimport { 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, theimport { 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 must end with a trailing platform-specific path separator [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']; }];
024#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v11. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
10 argument is now optional and defaults toimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v9. 9. 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']; }];
The
030 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
031 flags are supported nowv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Asynchronous file open. See the POSIX
58 documentation for more detailsimport { 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']; }];
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; seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
006import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The callback gets two arguments
038import * as fs from 'node:fs';
const fs = require['node:fs'];
Some characters [
59] are reserved under Windows as documented by Naming Files, Paths, and Namespaces. Under NTFS, if the filename contains a colon, Node. js will open a file system stream, as described by this MSDN pageimport { 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']; }];
Functions based on
64 exhibit this behavior as well.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
76,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
75, etcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
043#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v13. 1. 0, v12. 16. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
61 option was introducedv12. 12. 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']; }];
Added in. v12. 12. 0
Asynchronously open a directory. See the POSIX
62 documentation for more detailsimport { 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']; }];
Creates an , which contains all further functions for reading from and cleaning up the directory
The
17 option sets the encoding for theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 while opening the directory and subsequent read operationsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
051#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 10. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
28 parameter can now be anyimport * as fs from 'node:fs';
const fs = require['node:fs'];
056, or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
28 parameter can now be aimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
30 parameter can now beimport * as fs from 'node:fs';
const fs = require['node:fs'];
39v0. 0. 2import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 0. 2
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
28 . . The buffer that the data will be written toimport * as fs from 'node:fs';
const fs = require['node:fs'];
29 The position inimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 to write the data toimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 . . Specifies where to begin reading from in the file. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 isimport * as fs from 'node:fs';
const fs = require['node:fs'];
5 orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
070, data will be read from the current file position, and the file position will be updated. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 is an integer, the file position will be unchangedimport * as fs from 'node:fs';
const fs = require['node:fs'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Read data from the file specified by
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The callback is given the three arguments,
074import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
If this method is invoked as its
075ed version, it returns a promise for animport * as fs from 'node:fs';
const fs = require['node:fs'];
076 withimport * as fs from 'node:fs';
const fs = require['node:fs'];
077 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 propertiesimport * as fs from 'node:fs';
const fs = require['node:fs'];
079#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv13. 11. 0, v12. 17. 0
Đã thêm vào. v13. 11. 0, v12. 17. 0
v13. 11. 0, v12. 17. 0Options object can be passed in to make buffer, offset, length, and position optional
Similar to the
080 function, this version takes an optionalimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 object. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object is specified, it will default with the above valuesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
083#import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v18. 2. 0, v16. 17. 0
Similar to the
080 function, this version takes an optionalimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 object. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object is specified, it will default with the above valuesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 10. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
New option
66 was addedv10. 0. 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']; }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v6. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
08 parameter was addedv0. 1. 8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 8
Reads the contents of a directory. The callback gets two arguments
099 whereimport * as fs from 'node:fs';
const fs = require['node:fs'];
100 is an array of the names of the files in the directory excludingimport * as fs from 'node:fs';
const fs = require['node:fs'];
101 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
102import * as fs from 'node:fs';
const fs = require['node:fs'];
See the POSIX
103 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the filenames passed to the callback. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the filenames returned will be passed as objectsimport { 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']; }];
If
71 is set toimport { 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, theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
100 array will contain objectsimport * as fs from 'node:fs';
const fs = require['node:fs'];
111#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The error returned may be an
123 if more than one error is returnedv15. 2. 0, v14. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The options argument may include an AbortSignal to abort an ongoing readFile request
v10. 0. 0The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v5. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 will always be called withimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
5 as theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
124 parameter in case of successv5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
47 parameter can be a file descriptor nowv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 29
Asynchronously reads the entire contents of a file
1import { 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']; }];
The callback is passed two arguments
126, whereimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 is the contents of the fileimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
If no encoding is specified, then the raw buffer is returned
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { 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']; }];
When the path is a directory, the behavior of
75 andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
130 is platform-specific. On macOS, Linux, and Windows, an error will be returned. On FreeBSD, a representation of the directory's contents will be returnedimport * as fs from 'node:fs';
const fs = require['node:fs'];
It is possible to abort an ongoing request using an
131. If a request is aborted the callback is called with animport * as fs from 'node:fs';
const fs = require['node:fs'];
80import { 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']; }];
The
75 function buffers the entire file. To minimize memory costs, when possible prefer streaming viaimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
051import * as fs from 'node:fs';
const fs = require['node:fs'];
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
81 performsFile descriptors#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']; }];
Performance Considerations#
- Any specified file descriptor has to support reading
- If a file descriptor is specified as the
47, it will not be closed automaticallyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- The reading will begin at the current position. For example, if the file already had
137' and six bytes are read with the file descriptor, the call toimport * as fs from 'node:fs';
const fs = require['node:fs'];
75 with the same file descriptor, would giveimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
139, rather thanimport * as fs from 'node:fs';
const fs = require['node:fs'];
140import * as fs from 'node:fs';
const fs = require['node:fs'];
The
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 memoryimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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
080 directly and for application code to manage reading the full contents of the file itselfimport * as fs from 'node:fs';
const fs = require['node:fs'];
The Node. js GitHub issue #25741 provides more information and a detailed analysis on the performance of
75 for multiple file sizes in different Node. js versionsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
144#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Reads the contents of the symbolic link referred to by
47. The callback gets two argumentsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
155import * as fs from 'node:fs';
const fs = require['node:fs'];
See the POSIX
84 documentation for more detailsimport { 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']; }];
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the link path passed to the callback. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the link path returned will be passed as a objectimport { 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']; }];
161#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v13. 13. 0, v12. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v13. 13. 0, v12. 17. 0
Read from a file specified by
064 and write to an array ofimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
166s usingimport * as fs from 'node:fs';
const fs = require['node:fs'];
167import * 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. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, the data will be read from the current positionimport * as fs from 'node:fs';
const fs = require['node:fs'];
The callback will be given three arguments.
046,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
077, andimport * 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 fileimport * as fs from 'node:fs';
const fs = require['node:fs'];
If this method is invoked as its
075ed version, it returns a promise for animport * as fs from 'node:fs';
const fs = require['node:fs'];
076 withimport * as fs from 'node:fs';
const fs = require['node:fs'];
077 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
74 propertiesimport * as fs from 'node:fs';
const fs = require['node:fs'];
178#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev8. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Pipe/Socket resolve support was added
v7. 6. 0The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v6. 4. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Calling
188 now works again for various edge cases on Windowsv6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
189 parameter was removedv0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 1. 31
Asynchronously computes the canonical pathname by resolving
190,import * as fs from 'node:fs';
const fs = require['node:fs'];
191, and symbolic linksimport * as fs from 'node:fs';
const fs = require['node:fs'];
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
192, with some exceptionsimport * as fs from 'node:fs';
const fs = require['node:fs'];
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
192 implementation supportsimport * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 gets two argumentsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
195. May useimport * as fs from 'node:fs';
const fs = require['node:fs'];
196 to resolve relative pathsimport * as fs from 'node:fs';
const fs = require['node:fs'];
Only paths that can be converted to UTF8 strings are supported
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the path passed to the callback. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the path returned will be passed as a objectimport { 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']; }];
If
47 resolves to a socket or a pipe, the function will return a system dependent name for that objectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
202#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v9. 2. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v9. 2. 0
Asynchronous
192import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 gets two argumentsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
195import * as fs from 'node:fs';
const fs = require['node:fs'];
Only paths that can be converted to UTF8 strings are supported
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the path passed to the callback. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the path returned will be passed as a objectimport { 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']; }];
On Linux, when Node. js is linked against musl libc, the procfs file system must be mounted on
97 in order for this function to work. Glibc does not have this restrictionimport { 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']; }];
214#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
99 andimport { 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 WHATWGimport { 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']; }];
53 objects usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocol. Support is currently still experimentalv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Asynchronously rename file at
99 to the pathname provided asimport { 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 thatimport { 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 atimport { 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 callbackimport { 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']; }];
See also.
229import * 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']; }];
230#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Using
234 on aimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 that is a file is no longer permitted and results in animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504 error on Windows and animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 error on POSIXv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Using
234 on aimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 that does not exist is no longer permitted and results in aimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504 errorv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10 option is deprecated, using it triggers a deprecation warningv14. 14. 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']; }];
The
10 option is deprecated, useimport { 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']; }];
243 insteadv13. 3. 0, v12. 16. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
512 option is renamed toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513, and its default is 0. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 option has been removed, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515 errors use the same retry logic as other errors. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 option is now supported.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517 errors are now retriedv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10,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']; }];
512, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 options are now supportedv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameters can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
47 . .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js retries the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive directory removal. In recursive mode, operations are retried on failure. 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'];
01. Deprecatedimport * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Asynchronous
279. No arguments other than a possible exception are given to the completion callbackimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sử dụng
280 trên tệp [không phải thư mục] dẫn đến lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
504 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 trên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
To get a behavior similar to the
545 Unix command, useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 with optionsimport * as fs from 'node:fs';
const fs = require['node:fs'];
547import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
286#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv17. 3. 0, v16. 14. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv14. 14. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v14. 14. 0
47 . .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, exceptions will be ignored ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 does not exist. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js will retry the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive removal. In recursive mode operations are retried on failure. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Asynchronously removes files and directories [modeled on the standard POSIX
573 utility]. No arguments other than a possible exception are given to the completion callbackimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
315#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Asynchronous
326. The callback gets two argumentsimport * as fs from 'node:fs';
const fs = require['node:fs'];
166 whereimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
167 is an objectimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
In case of an error, the
329 will be one of Common System Errorsimport * as fs from 'node:fs';
const fs = require['node:fs'];
Using
330 to check for the existence of a file before callingimport * as fs from 'node:fs';
const fs = require['node:fs'];
64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, orimport { 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 availableimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
To check if a file exists without manipulating it afterwards,
73 is recommendedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
For example, given the following directory structure
4import { 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']; }];
Chương trình tiếp theo sẽ kiểm tra số liệu thống kê của các đường dẫn đã cho
5import { 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']; }];
The resulting output will resemble
6import { 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']; }];
335#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v12. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
If the
577 argument is left undefined, Node will autodetectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 type and automatically selectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
580 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
581v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
579 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 objects usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocol. Support is currently still experimentalv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Creates the link called
47 pointing toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579. No arguments other than a possible exception are given to the completion callbackimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
See the POSIX
349 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
The
577 argument is only available on Windows and ignored on other platforms. It can be set toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
583,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
585. If theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
577 argument is not a string, Node. js will autodetectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 type and useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
583. If theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 does not exist,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
584 will be used. Windows junction points require the destination path to be absolute. When usingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
585, theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 argument will automatically be normalized to absolute pathimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Relative targets are relative to the link's parent directory
7import { 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']; }];
The above example creates a symbolic link
362 which points toimport * as fs from 'node:fs';
const fs = require['node:fs'];
363 in the same directoryimport * as fs from 'node:fs';
const fs = require['node:fs'];
8import { 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']; }];
364import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The error returned may be an
123 if more than one error is returnedv10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 8. 6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added 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,
372 is calledimport * as fs from 'node:fs';
const fs = require['node:fs'];
Passing a file descriptor is deprecated and may result in an error being thrown in the future
See the POSIX
373 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
374#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Asynchronously removes a file or symbolic link. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
384 will not work on a directory, empty or otherwise. To remove a directory, useimport * as fs from 'node:fs';
const fs = require['node:fs'];
280import * as fs from 'node:fs';
const fs = require['node:fs'];
See the POSIX
00 documentation for more detailsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
387#import * as fs from 'node:fs';
const fs = require['node:fs'];
Stop watching for changes on
12. Ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
389 is specified, only that particular listener is removed. Otherwise, all listeners are removed, effectively stopping watching ofimport * as fs from 'node:fs';
const fs = require['node:fs'];
12import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Gọi
391 với tên tệp không được xem là không hoạt động, không phải lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Using
24 is more efficient thanimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
393 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
391.import * as fs from 'node:fs';
const fs = require['node:fs'];
24 should be used instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
393 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
391 when possibleimport * as fs from 'node:fs';
const fs = require['node:fs'];
398import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev8. 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, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 are no longer valid time specifiersv7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v4. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Numeric strings,
07, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 are now allowed time specifiersv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 4. 2
Change the file system timestamps of the object referenced by
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
03 andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04 arguments follow these rulesimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Values can be either numbers representing Unix epoch time in seconds,
05s, or a numeric string likeimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
06import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- If the value can not be converted to a number, or is
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08, orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09, animport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 will be thrownimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
422#import * as fs from 'node:fs';
const fs = require['node:fs'];
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
12 parameter can be a WHATWGimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
53 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv7. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The passed
08 object will never be modifiedv0. 5. 10import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 5. 10
12 . .import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
14 Indicates whether the process should continue to run as long as files are being watched. Default.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 Indicates whether all subdirectories should be watched, or only the current directory. This applies when a directory is specified, and only on supported platforms [See caveats]. Default.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']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
17 Specifies the character encoding to be used for the filename passed to the listener. Default.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
20 allows closing the watcher with an AbortSignalimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
389 . Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Returns.
Watch for changes on
12, whereimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
12 is either a file or a directoryimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The second argument is optional. If
08 is provided as a string, it specifies theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17. Otherwiseimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 should be passed as an objectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The listener callback gets two arguments
443.import * as fs from 'node:fs';
const fs = require['node:fs'];
444 is eitherimport * as fs from 'node:fs';
const fs = require['node:fs'];
23 orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
446, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
12 is the name of the file which triggered the eventimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
On most platforms,
23 is emitted whenever a filename appears or disappears in the directoryimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The listener callback is attached to the
446 event fired by , but it is not the same thing as theimport * as fs from 'node:fs';
const fs = require['node:fs'];
446 value ofimport * as fs from 'node:fs';
const fs = require['node:fs'];
444import * as fs from 'node:fs';
const fs = require['node:fs'];
If a
20 is passed, aborting the corresponding AbortController will close the returned Caveats#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
453 API is not 100% consistent across platforms, and is unavailable in some situationsimport * as fs from 'node:fs';
const fs = require['node:fs'];
On Windows, no events will be emitted if the watched directory is moved or renamed. An
528 error is reported when the watched directory is deletedAvailability#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
This feature depends on the underlying operating system providing a way to be notified of filesystem changes
- On Linux systems, this uses
455import * as fs from 'node:fs';
const fs = require['node:fs'];
- On BSD systems, this uses
456import * as fs from 'node:fs';
const fs = require['node:fs'];
- On macOS, this uses
456 for files andimport * as fs from 'node:fs';
const fs = require['node:fs'];
458 for directoriesimport * as fs from 'node:fs';
const fs = require['node:fs'];
- On SunOS systems [including Solaris and SmartOS], this uses
459import * as fs from 'node:fs';
const fs = require['node:fs'];
- On Windows systems, this feature depends on
460import * as fs from 'node:fs';
const fs = require['node:fs'];
- On AIX systems, this feature depends on
461, which must be enabledimport * as fs from 'node:fs';
const fs = require['node:fs'];
- On IBM i systems, this feature is not supported
If the underlying functionality is not available for some reason, then
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 Dockerimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
It is still possible to use
393, which uses stat polling, but this method is slower and less reliableInodes#import * as fs from 'node:fs';
const fs = require['node:fs'];
On Linux and macOS systems,
24 resolves the path to an inode and watches the inode. Nếu đường dẫn đã xem bị xóa và tạo lại, nó sẽ được gán một nút mới. 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. This is expected behaviorimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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 argument#Providing
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 thatimport { 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 isimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
9import { 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']; }];
469#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 5. 0
The
470 option is now supportedv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
12 parameter can be a WHATWGimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
53 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Watch for changes on
12. The callbackimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
389 will be called each time the file is accessedimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
08 có thể được bỏ qua. Nếu được cung cấp, nó phải là một đối tượng. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object may contain a boolean namedimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
14 that indicates whether the process should continue to run as long as files are being watched. Theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 object may specify animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
480 property indicating how often the target should be polled in millisecondsimport * as fs from 'node:fs';
const fs = require['node:fs'];
The
389 gets two arguments the current stat object and the previous stat objectimport * as fs from 'node:fs';
const fs = require['node:fs'];
50import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
These stat objects are instances of
482. If theimport * as fs from 'node:fs';
const fs = require['node:fs'];
470 option isimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, the numeric values in these objects are specified asimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
485simport * as fs from 'node:fs';
const fs = require['node:fs'];
To be notified when the file was modified, not just accessed, it is necessary to compare
486 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
487import * as fs from 'node:fs';
const fs = require['node:fs'];
When an
488 operation results in animport * as fs from 'node:fs';
const fs = require['node:fs'];
504 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. 10import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Using
24 is more efficient thanimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
488 andimport * 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 ofimport * as fs from 'node:fs';
const fs = require['node:fs'];
488 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
492 when possibleimport * as fs from 'node:fs';
const fs = require['node:fs'];
When a file being watched by
393 disappears and reappears, then the contents ofimport * 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 ofimport * as fs from 'node:fs';
const fs = require['node:fs'];
497 in the first callback event [its disappearance]import * as fs from 'node:fs';
const fs = require['node:fs'];
This happens when
- the file is deleted, followed by a restore
- the file is renamed and then renamed a second time back to its original name
499#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v14. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
28 parameter won't coerce unsupported input to strings anymorev10. 10. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
28 parameter can now be anyimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 4. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
28 parameter can now be aimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v7. 2. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
29 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 parameters are optional nowv7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 0. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 0. 2
Write
28 to the file specified byimport * as fs from 'node:fs';
const fs = require['node:fs'];
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
29 determines the part of the buffer to be written, andimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 is an integer specifying the number of bytes to writeimport * 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. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, the data will be written at the current position. Seeimport * as fs from 'node:fs';
const fs = require['node:fs'];
04import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The callback will be given three arguments
521 whereimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 specifies how many bytes were written fromimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28import * as fs from 'node:fs';
const fs = require['node:fs'];
If this method is invoked as its
075ed version, it returns a promise for animport * as fs from 'node:fs';
const fs = require['node:fs'];
076 withimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28 propertiesimport * as fs from 'node:fs';
const fs = require['node:fs'];
It is unsafe to use
528 multiple times on the same file without waiting for the callback. For this scenario,import * as fs from 'node:fs';
const fs = require['node:fs'];
42 is recommendedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
On Linux, positional writes don't 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
530#import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v18. 3. 0, v16. 17. 0
Write
28 to the file specified byimport * as fs from 'node:fs';
const fs = require['node:fs'];
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Similar to the above
533 function, this version takes an optionalimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 object. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object is specified, it will default with the above valuesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
536#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv19. 0. 0
Chuyển đến tham số
15 một đối tượng có chức năngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 riêng không còn được hỗ trợv17. 8. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Passing to the
15 parameter an object with an ownimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 function is deprecatedv14. 12. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
15 parameter will stringify an object with an explicitimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 functionv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
15 parameter won't coerce unsupported input to strings anymorev10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 2. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
31 parameter is optional nowv7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v0. 11. 5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 11. 5
Write
15 to the file specified byimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Ifimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
15 is not a string, an exception is thrownimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 refers to the offset from the beginning of the file where this data should be written. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
169 the data will be written at the current position. Seeimport * as fs from 'node:fs';
const fs = require['node:fs'];
04import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 is the expected string encodingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The callback will receive the arguments
555 whereimport * 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. Seeimport * as fs from 'node:fs';
const fs = require['node:fs'];
557import * as fs from 'node:fs';
const fs = require['node:fs'];
It is unsafe to use
528 multiple times on the same file without waiting for the callback. For this scenario,import * as fs from 'node:fs';
const fs = require['node:fs'];
42 is recommendedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
On Linux, positional writes don't 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
On Windows, if the file descriptor is connected to the console [e. g.
560 orimport * 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 theimport * as fs from 'node:fs';
const fs = require['node:fs'];
562 command. See the chcp docs for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
563#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv19. 0. 0
Chuyển đến tham số
15 một đối tượng có chức năngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 riêng không còn được hỗ trợv18. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v17. 8. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Passing to the
15 parameter an object with an ownimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 function is deprecatedv16. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The error returned may be an
123 if more than one error is returnedv15. 2. 0, v14. 17. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The options argument may include an AbortSignal to abort an ongoing writeFile request
v14. 12. 0The
08 parameter will stringify an object with an explicitimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 functionv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter won't coerce unsupported input to strings anymorev10. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
08 parameter can now be anyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
056 or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 parameter is no longer optional. Not passing it will throw aimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
83 at runtimev7. 4. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
08 parameter can now be aimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
059v7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
49 parameter is no longer optional. Not passing it will emit a deprecation warning with id DEP0013v5. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
581 parameter can be a file descriptor nowv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 29
When
581 is a filename, asynchronously writes data to the file, replacing the file if it 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'];
08 can be a string or a bufferimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
When
581 is a file descriptor, the behavior is similar to callingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 directly [which is recommended]. See the notes below on using a file descriptorimport * as fs from 'node:fs';
const fs = require['node:fs'];
The
17 option is ignored ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 is a bufferimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
51import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
52import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
It is unsafe to use
76 multiple times on the same file without waiting for the callback. For this scenario,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
42 is recommendedimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Similarly to
81 -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']; }];
45 is a convenience method that performs multipleimport { 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 usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
42import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
It is possible to use an to cancel an
76. Cancelation is "best effort", and some amount of data is likely still to be writtenimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
45 performsUsingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
76 with file descriptors#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
When
581 is a file descriptor, the behavior is almost identical to directly callingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 likeimport * as fs from 'node:fs';
const fs = require['node:fs'];
53import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The difference from directly calling
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, whereasimport * as fs from 'node:fs';
const fs = require['node:fs'];
76 retries until the data is entirely written [or an error occurs]import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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
76 is called twice in a row, first to write the stringimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
608, then to write the stringimport * as fs from 'node:fs';
const fs = require['node:fs'];
609, the file would containimport * 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 onlyimport * as fs from 'node:fs';
const fs = require['node:fs'];
609import * as fs from 'node:fs';
const fs = require['node:fs'];
612#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v12. 9. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v12. 9. 0
Write an array of
166s to the file specified byimport * as fs from 'node:fs';
const fs = require['node:fs'];
064 usingimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
45import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 is the offset from the beginning of the file where this data should be written. Ifimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, the data will be written at the current positionimport * as fs from 'node:fs';
const fs = require['node:fs'];
The callback will be given three arguments.
046,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74.import * as fs from 'node:fs';
const fs = require['node:fs'];
27 is how many bytes were written fromimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74import * as fs from 'node:fs';
const fs = require['node:fs'];
If this method is
075ed, it returns a promise for animport * as fs from 'node:fs';
const fs = require['node:fs'];
076 withimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74 propertiesimport * as fs from 'node:fs';
const fs = require['node:fs'];
It is unsafe to use
630 multiple times on the same file without waiting for the callback. For this scenario, useimport * as fs from 'node:fs';
const fs = require['node:fs'];
42import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
On Linux, positional writes don't 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
Synchronous API#
The synchronous APIs perform all operations synchronously, blocking the event loop until the operation completes or fails
632#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 11. 15import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 11. 15
Synchronously tests a user's permissions for the file or directory specified by
47. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 valueimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 File access constants for possible values ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu bất kỳ kiểm tra khả năng truy cập nào không thành công, một
10 sẽ bị ném. Otherwise, the method will returnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
647#import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 0. 0
The passed
08 object will never be modifiedv5. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
581 parameter can be a file descriptor nowv0. 6. 7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 6. 7
Synchronously append data to a file, creating the file if it does not yet exist.
08 can be a string or aimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
If
08 is a string, then it specifies the encodingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
55import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 may be specified as a numeric file descriptor that has been opened for appending [usingimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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]. The file descriptor will not be closed automaticallyimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
657#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 6. 7import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 6. 7
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
006import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
See the POSIX
07 documentation for more detailimport * as fs from 'node:fs';
const fs = require['node:fs'];
663#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 97import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 97
Synchronously changes owner and group of a file. Returns
6. This is the synchronous version ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
668import * as fs from 'node:fs';
const fs = require['node:fs'];
See the POSIX
02 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
670#import * as fs from 'node:fs';
const fs = require['node:fs'];
Closes the file descriptor. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Calling
672 on any file descriptor [import * as fs from 'node:fs';
const fs = require['node:fs'];
064] that is currently in use through any otherimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
56 operation may lead to undefined behaviorimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
066 documentation for more detailimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
676#import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv14. 0. 0
Changed
10 argument toimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 and imposed stricter type validationv8. 5. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v8. 5. 0
Synchronously copies
72 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Returnsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
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 destinationimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
48 is an optional integer that specifies 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]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 existsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is usedimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
689#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv17. 6. 0, v16. 15. 0
Accepts an additional
86 option to specify whether to perform path resolution for symlinksv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v16. 7. 0
72 . source path to copyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 path to copy toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 dereference symlinks. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 isimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01, and the destination exists, throw an error. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Function to filter copied files/directories. Returnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 to ignore it. Default.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 overwrite existing file or directory. The copy operation will ignore errors if you set this to false and the destination exists. Use theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. 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'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Whenimport { 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 timestamps fromimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 will be preserved. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 copy directories recursively Default.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']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, path resolution for symlinks will be skipped. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
Sao chép đồng bộ toàn bộ cấu trúc thư mục từ
72 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, bao gồm các thư mục con và tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
When copying a directory to another directory, globs are not supported and behavior is similar to
18import { 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']; }];
719#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Returns
97 if the path 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'];
01 otherwiseimport * as fs from 'node:fs';
const fs = require['node:fs'];
For detailed information, see the documentation of the asynchronous version of this API.
047import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
047 is deprecated, butimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
727 is not. Theimport * as fs from 'node:fs';
const fs = require['node:fs'];
49 parameter toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
047 accepts parameters that are inconsistent with other Node. js callbacks.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
727 does not use a callbackimport * as fs from 'node:fs';
const fs = require['node:fs'];
56import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
731#import * as fs from 'node:fs';
const fs = require['node:fs'];
Sets the permissions on the file. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
061 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
734#import * as fs from 'node:fs';
const fs = require['node:fs'];
Sets the owner of the file. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
069 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
737#import * as fs from 'node:fs';
const fs = require['node:fs'];
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
24 documentation for details. Returnsimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
740#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 5. 0
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv0. 1. 95import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 95
Retrieves the for the file descriptor
See the POSIX
086 documentation for more detailimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
743#import * as fs from 'node:fs';
const fs = require['node:fs'];
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
83 documentation for more detail. Returnsimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
746import * as fs from 'node:fs';
const fs = require['node:fs'];
Truncates the file descriptor. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
For detailed information, see the documentation of the asynchronous version of this API.
372import * as fs from 'node:fs';
const fs = require['node:fs'];
749import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv4. 1. 0
Numeric strings,
07, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 are now allowed time specifiersv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 4. 2
Synchronous version of
752. Returnsimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
754#import * as fs from 'node:fs';
const fs = require['node:fs'];
Changes the permissions on a symbolic link. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
This method is only implemented on macOS
See the POSIX
127 documentation for more detailimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
757#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 6. 0
This API is no longer deprecated
v0. 4. 7Documentation-only deprecation
Set the owner for the path. Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
135 documentation for more detailsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
760import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v14. 5. 0, v12. 19. 0
Change the file system timestamps of the symbolic link referenced by
47. Returnsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6, or throws an exception when parameters are incorrect or the operation fails. This is the synchronous version ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
763import * as fs from 'node:fs';
const fs = require['node:fs'];
764import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
Các tham số
24 và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 có thể là các đối tượng WHATWGimport { 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']; }];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Creates a new link from the
24 to theimport { 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. Xem tài liệu POSIXimport { 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 để biết thêm chi tiết. Returnsimport { 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 { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
773#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv15. 3. 0, v14. 17. 0
Accepts a
774 option to specify whether an exception should be thrown if the entry does not existv10. 5. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 30import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 30
Retrieves the for the symbolic link referred to by
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
31 để biết thêm chi tiếtimport { 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']; }];
781#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv13. 11. 0, v12. 17. 0
In
10 mode, the first created path is returned nowv10. 12. 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']; }];
Đối số thứ hai bây giờ có thể là một đối tượng
08 với các thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 và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']; }];
48v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Synchronously creates a directory. Returns
6, or ifimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 isimport { 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, the first directory path created. This is the synchronous version ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
197import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
001 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
794#import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 5. 0, v14. 18. 0
Tham số
41 hiện chấp nhận một chuỗi rỗngv5. 10. 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']; }];
Added in. v5. 10. 0
Returns the created directory path
For detailed information, see the documentation of the asynchronous version of this API.
018import * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
08 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 chỉ định mã hóa ký tự sẽ sử dụngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
799#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv13. 1. 0, v12. 16. 0
The
61 option was introducedv12. 12. 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']; }];
Added in. v12. 12. 0
Synchronously open a directory. See
62import { 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']; }];
Creates an , which contains all further functions for reading from and cleaning up the directory
The
17 option sets the encoding for theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 while opening the directory and subsequent read operationsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
804#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv11. 1. 0
The
10 argument is now optional and defaults toimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v9. 9. 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']; }];
The
030 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
031 flags are supported nowv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Trả về một số nguyên đại diện cho bộ mô tả tệp
For detailed information, see the documentation of the asynchronous version of this API.
64import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
813#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 10. 0
New option
66 was addedv7. 6. 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']; }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Reads the contents of the directory
See the POSIX
103 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the filenames returned. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 được đặt thànhimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, tên tệp được trả về sẽ được chuyển dưới dạng đối tượngimport { 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']; }];
If
71 is set toimport { 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, the result will contain objectsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
825#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv5. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a file descriptor nowv0. 1. 8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 8
Returns the contents of the
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
For detailed information, see the documentation of the asynchronous version of this API.
75import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
If the
17 option is specified then this function returns a string. Otherwise it returns a bufferimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Similar to
75, when the path is a directory, the behavior ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
130 is platform-specificimport * as fs from 'node:fs';
const fs = require['node:fs'];
835import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Returns the symbolic link's string value
See the POSIX
84 documentation for more detailsimport { 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']; }];
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the link path returned. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the link path returned will be passed as a objectimport { 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']; }];
844#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv10. 10. 0
The
28 parameter can now be anyimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
30 parameter can now beimport * as fs from 'node:fs';
const fs = require['node:fs'];
39v0. 1. 21import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 1. 21
Returns the number of
077import * as fs from 'node:fs';
const fs = require['node:fs'];
For detailed information, see the documentation of the asynchronous version of this API.
080import * as fs from 'node:fs';
const fs = require['node:fs'];
852#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv13. 13. 0, v12. 17. 0
Added in. v13. 13. 0, v12. 17. 0
v13. 13. 0, v12. 17. 0Đối tượng tùy chọn có thể được chuyển vào để tạo độ lệch, độ dài và vị trí tùy chọn
Returns the number of
077import * as fs from 'node:fs';
const fs = require['node:fs'];
Similar to the above
854 function, this version takes an optionalimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 object. If noimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 object is specified, it will default with the above valuesimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
For detailed information, see the documentation of the asynchronous version of this API.
080import * as fs from 'node:fs';
const fs = require['node:fs'];
858#import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v13. 13. 0, v12. 17. 0
For detailed information, see the documentation of the asynchronous version of this API.
859import * as fs from 'node:fs';
const fs = require['node:fs'];
860#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv8. 0. 0
Pipe/Socket resolve support was added
v7. 6. 0The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv6. 4. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Calling
864 now works again for various edge cases on Windowsv6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
189 parameter was removedv0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 1. 31
Returns the resolved pathname
For detailed information, see the documentation of the asynchronous version of this API.
866import * as fs from 'node:fs';
const fs = require['node:fs'];
867#import * as fs from 'node:fs';
const fs = require['node:fs'];
Synchronous
192import * as fs from 'node:fs';
const fs = require['node:fs'];
Only paths that can be converted to UTF8 strings are supported
The optional
08 argument can be a string specifying an encoding, or an object with animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
17 property specifying the character encoding to use for the path returned. If theimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 is set toimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, the path returned will be passed as a objectimport { 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']; }];
On Linux, when Node. js is linked against musl libc, the procfs file system must be mounted on
97 in order for this function to work. Glibc does not have this restrictionimport { 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']; }];
874#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
99 andimport { 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 WHATWGimport { 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']; }];
53 objects usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocol. Support is currently still experimentalv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Renames the file from
99 toimport { 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. Returnsimport { 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 { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
See the POSIX
229 documentation for more detailsimport * as fs from 'node:fs';
const fs = require['node:fs'];
883#import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 0. 0
Sử dụng
884 trên một tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 trên POSIXv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Việc sử dụng
884 trên mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không tồn tại sẽ không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
504v16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10 option is deprecated, using it triggers a deprecation warningv14. 14. 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']; }];
The
10 option is deprecated, useimport { 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']; }];
893 insteadv13. 3. 0, v12. 16. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
512 option is renamed toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513, and its default is 0. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 option has been removed, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515 errors use the same retry logic as other errors. Theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 option is now supported.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517 errors are now retriedv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
10,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']; }];
512, andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
514 options are now supportedv7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 parameters can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
47 . .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js retries the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive directory removal. In recursive mode, operations are retried on failure. 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'];
01. Deprecatedimport * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Synchronous
279. Returnsimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Using
927 on a file [not a directory] results in animport * as fs from 'node:fs';
const fs = require['node:fs'];
504 error on Windows and animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
505 error on POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
To get a behavior similar to the
545 Unix command, useimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
931 with optionsimport * as fs from 'node:fs';
const fs = require['node:fs'];
547import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
933#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv17. 3. 0, v16. 14. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv14. 14. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v14. 14. 0
47 . .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 Whenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, exceptions will be ignored ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 does not exist. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
513 If animport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
524,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
515,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
517,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
527, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 error is encountered, Node. js will retry the operation with a linear backoff wait ofimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
516 milliseconds longer on each try. This option represents the number of retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Ifimport { 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, perform a recursive directory removal. In recursive mode operations are retried on failure. 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'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
516 The amount of time in milliseconds to wait between retries. This option is ignored if theimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 option is notimport { 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. 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'];
539import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đồng bộ xóa các tệp và thư mục [được mô hình hóa trên tiện ích POSIX
573 tiêu chuẩn]. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
962#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv15. 3. 0, v14. 17. 0
Accepts a
774 option to specify whether an exception should be thrown if the entry does not existv10. 5. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Accepts an additional
08 object to specify whether the numeric values returned should be bigintv7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Retrieves the for the path
968import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv12. 0. 0
If the
577 argument is left undefined, Node will autodetectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
579 type and automatically selectimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
580 orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
581v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
579 andimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 objects usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocol. Support is currently still experimentalv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 31
Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
978import * as fs from 'node:fs';
const fs = require['node:fs'];
979import * as fs from 'node:fs';
const fs = require['node:fs'];
Cắt bớt tập tin. Trả lại
6. Một bộ mô tả tệp cũng có thể được chuyển làm đối số đầu tiên. Trong trường hợp này,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
981 được gọi làimport * as fs from 'node:fs';
const fs = require['node:fs'];
Passing a file descriptor is deprecated and may result in an error being thrown in the future
982import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv7. 6. 0
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 1. 21
Đồng bộ
00. Trả lạiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
988import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv8. 0. 0
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 are no longer valid time specifiersv7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
47 parameter can be a WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 object usingimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 protocolv4. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Numeric strings,
07, andimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 are now allowed time specifiersv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v0. 4. 2
Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
118import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
999#import * as fs from 'node:fs';
const fs = require['node:fs'];
HistoryVersionChangesv19. 0. 0
Chuyển đến tham số
08 một đối tượng có chức năngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 riêng không còn được hỗ trợv17. 8. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chuyển đến tham số
08 một đối tượng có hàm riêngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 không được dùng nữav14. 12. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter will stringify an object with an explicitimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 functionv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter won't coerce unsupported input to strings anymorev10. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
The
08 parameter can now be anyimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
056 or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
08 parameter can now be aimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
059v5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
581 parameter can be a file descriptor nowv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v0. 1. 29
Returns
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
The
48 option only affects the newly created file. Seeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 for more detailsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
76import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
017#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
The
28 parameter won't coerce unsupported input to strings anymorev10. 10. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
28 parameter can now be anyimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 or aimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
28 parameter can now be aimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v7. 2. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
The
29 andimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 parameters are optional nowv0. 1. 21import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 1. 21
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
026import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Added in. v18. 3. 0, v16. 17. 0
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
026import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
The
15 parameter won't coerce unsupported input to strings anymorev7. 2. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The
31 parameter is optional nowv0. 11. 5import * as fs from 'node:fs';
const fs = require['node:fs'];
Added in. v0. 11. 5
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
032import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
630import * as fs from 'node:fs';
const fs = require['node:fs'];
Những vật thông thường#
Các đối tượng chung được chia sẻ bởi tất cả các biến thể API hệ thống tệp [lời hứa, gọi lại và đồng bộ]
Class.
035#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một lớp đại diện cho một luồng thư mục
Được tạo bởi
036,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
037 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
038import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 * as fs from 'node:fs';
const fs = require['node:fs'];
When using the async iterator, the object will be automatically closed after the iterator exits
039#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng xử lý tài nguyên cơ bản của thư mục một cách không đồng bộ. Các lần đọc tiếp theo sẽ dẫn đến lỗi
Một lời hứa được trả lại sẽ được giải quyết sau khi tài nguyên đã bị đóng
040#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
HistoryVersionChangesv18. 0. 0
Passing an invalid callback to the
49 argument now throwsimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 instead ofimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v12. 12. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Added in. v12. 12. 0
Đóng xử lý tài nguyên cơ bản của thư mục một cách không đồng bộ. Các lần đọc tiếp theo sẽ dẫn đến lỗi
49 sẽ được gọi sau khi xử lý tài nguyên đã bị đóngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
045#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng đồng bộ xử lý tài nguyên cơ bản của thư mục. Các lần đọc tiếp theo sẽ dẫn đến lỗi
046#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn chỉ đọc của thư mục này như được cung cấp cho
036,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
037 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
038import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc không đồng bộ mục nhập thư mục tiếp theo qua
103 dưới dạngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Một lời hứa được trả lại sẽ được giải quyết bằng , hoặc
5 nếu không còn mục nhập thư mục nào để đọcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
053#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc không đồng bộ mục nhập thư mục tiếp theo qua
103 dưới dạngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sau khi đọc xong,
49 sẽ được gọi với dấu , hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
5 nếu không còn mục nhập thư mục nào để đọcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
057#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc đồng bộ mục nhập thư mục tiếp theo dưới dạng. Xem tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu không còn mục nào trong thư mục để đọc, thì sẽ trả về
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
060#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lặp lại không đồng bộ trên thư mục cho đến khi tất cả các mục đã được đọc. Tham khảo tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Các mục được trả về bởi trình vòng lặp không đồng bộ luôn là một. Trường hợp
5 từimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
050 được xử lý nội bộimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem ví dụ
Các mục nhập thư mục được trình vòng lặp này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
Lớp.
064#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một đại diện của một mục nhập thư mục, có thể là một tệp hoặc thư mục con trong thư mục, được trả về bằng cách đọc từ một. Mục nhập thư mục là sự kết hợp của các cặp tên tệp và loại tệp
Ngoài ra, khi
065 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
066 được gọi với tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
66 được đặt thànhimport { 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, mảng kết quả được lấp đầy bằng các đối tượng, thay vì các chuỗi hoặc simport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
069#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị khốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
071#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị ký tựimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
073#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả thư mục hệ thống tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
075#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả ống nhập trước xuất trước [FIFO]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
077#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một tệp thông thườngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
079#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
081#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một liên kết tượng trưngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
083#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tên tệp mà đối tượng này đề cập đến. Loại giá trị này được xác định bởi
65 được chuyển đếnimport * as fs from 'node:fs';
const fs = require['node:fs'];
065 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
066import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
087#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Gọi thành công phương thức
24 sẽ trả về một đối tượng mớiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Tất cả các đối tượng phát ra sự kiện
446 bất cứ khi nào một tệp đã xem cụ thể được sửa đổiBiến cố.import * as fs from 'node:fs';
const fs = require['node:fs'];
446#import * as fs from 'node:fs';
const fs = require['node:fs'];
444 Loại sự kiện thay đổi đã xảy raimport * as fs from 'node:fs';
const fs = require['node:fs'];
12. Tên tệp đã thay đổi [nếu có/có liên quan]import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Phát ra khi có gì đó thay đổi trong thư mục hoặc tệp đã xem. Xem thêm chi tiết trong
24import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đối số
12 có thể không được cung cấp tùy thuộc vào sự hỗ trợ của hệ điều hành. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
12 được cung cấp, thì nó sẽ được cung cấp dưới dạng nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
24 được gọi với tùy chọnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
17 của nó được đặt thànhimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
70, nếu không thì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']; }];
12 sẽ là chuỗi UTF-8Event.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi người xem ngừng theo dõi các thay đổi. Đối tượng đã đóng không còn sử dụng được trong trình xử lý sự kiện
Biến cố.04#import * as fs from 'node:fs';
const fs = require['node:fs'];
Xuất hiện khi xảy ra lỗi trong khi xem tệp. Đối tượng bị lỗi không còn sử dụng được trong trình xử lý sự kiện
102#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ngừng theo dõi các thay đổi trên đã cho. Sau khi dừng, đối tượng không còn sử dụng được nữa
103#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, yêu cầu Node. vòng lặp sự kiện js không thoát miễn là nó đang hoạt động. Gọi
103 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Theo mặc định, tất cả các đối tượng đều được "ref'ed", khiến việc gọi
103 thông thường không cần thiết trừ khi trước đó đã gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, đối tượng hoạt động sẽ không yêu cầu Nút. vòng lặp sự kiện js để duy trì hoạt động. Nếu không có hoạt động nào khác giữ cho vòng lặp sự kiện chạy, quy trình có thể thoát trước khi lệnh gọi lại của đối tượng được gọi. Gọi
106 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
109#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Một cuộc gọi thành công đến phương thức
393 sẽ trả về một đối tượng mớiimport * as fs from 'node:fs';
const fs = require['node:fs'];
103#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, yêu cầu Node. vòng lặp sự kiện js không thoát miễn là nó đang hoạt động. Gọi
103 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Theo mặc định, tất cả các đối tượng đều được "ref'ed", khiến việc gọi
103 thông thường không cần thiết trừ khi trước đó đã gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, đối tượng hoạt động sẽ không yêu cầu Nút. vòng lặp sự kiện js để duy trì hoạt động. Nếu không có hoạt động nào khác giữ cho vòng lặp sự kiện chạy, quy trình có thể thoát trước khi lệnh gọi lại của đối tượng được gọi. Gọi
106 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
117#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các phiên bản của được tạo và trả về bằng cách sử dụng hàm
051Event.import * as fs from 'node:fs';
const fs = require['node:fs'];
05#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi bộ mô tả tệp cơ bản của đã bị đóng
Biến cố.056#import * as fs from 'node:fs';
const fs = require['node:fs'];
Được phát ra khi bộ mô tả tệp của đã được mở
Biến cố.121#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phát ra khi đã sẵn sàng để được sử dụng
Cháy ngay sau
056import * as fs from 'node:fs';
const fs = require['node:fs'];
123#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng byte đã được đọc cho đến nay
124#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn đến tệp mà luồng đang đọc từ đó như được chỉ định trong đối số đầu tiên của
051. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 được truyền dưới dạng chuỗi, thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 sẽ là chuỗi. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được chuyển thành a , thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 sẽ là a. Nếu chỉ địnhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 thìimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
124 sẽ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
133#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v11. 2. 0, v10. 16. 0
Thuộc tính này là
97 nếu tệp cơ bản chưa được mở, tôi. e. trước khi sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được phát raimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
136#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv8. 1. 0
Đã thêm lần dưới dạng số
v0. 1. 21Added in. v0. 1. 21
Một đối tượng cung cấp thông tin về một tập tin
Các đối tượng được trả về từ
330,import * as fs from 'node:fs';
const fs = require['node:fs'];
138,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
139 và các đối tượng đồng bộ của chúng thuộc loại này. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
470 trongimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 được truyền cho các phương thức đó là đúng, thì các giá trị số sẽ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
470 thay vìimport * as fs from 'node:fs';
const fs = require['node:fs'];
77 và đối tượng sẽ chứa các thuộc tính chính xác nano giây bổ sung có hậu tố làimport * as fs from 'node:fs';
const fs = require['node:fs'];
144import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
58import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phiên bản
470import * as fs from 'node:fs';
const fs = require['node:fs'];
59import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
146#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị khốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
148#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị ký tựimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
150#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả thư mục hệ thống tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu đối tượng được lấy từ
138, phương thức này sẽ luôn trả vềimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01. Điều này là doimport * as fs from 'node:fs';
const fs = require['node:fs'];
138 trả về thông tin về chính liên kết tượng trưng chứ không phải đường dẫn mà nó giải quyếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
155#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả ống nhập trước xuất trước [FIFO]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
157#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một tệp thông thườngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
159#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
161#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một liên kết tượng trưngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phương pháp này chỉ hợp lệ khi sử dụng
138import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
164#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng của thiết bị chứa tệp
165#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số "Inode" cụ thể của hệ thống tệp cho tệp
166#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một trường bit mô tả loại tệp và chế độ
167#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng liên kết cứng tồn tại cho tệp
168#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Định danh người dùng dạng số của người dùng sở hữu tệp [POSIX]
169#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng nhóm số của nhóm sở hữu tệp [POSIX]
170#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng thiết bị số nếu tệp đại diện cho một thiết bị
171#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Kích thước của tệp tính bằng byte
Nếu hệ thống tệp cơ bản không hỗ trợ nhận kích thước của tệp, điều này sẽ là
39import * as fs from 'node:fs';
const fs = require['node:fs'];
173#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Kích thước khối hệ thống tệp cho các thao tác i/o
174#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số khối được phân bổ cho tệp này
175import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được truy cập được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
176import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
177import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng trạng thái tệp được thay đổi được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
178import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết thời gian tạo tệp này được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
179import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng tệp này được truy cập được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
181import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
183import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng trạng thái tệp được thay đổi được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
185import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết thời gian tạo tệp này được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
187import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối tệp này được truy cập
188import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi
189import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối trạng thái tệp được thay đổi
190import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết thời gian tạo tệp này
Giá trị thời gian thống kêCác thuộc tính
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 là các giá trị số chứa thời gian tương ứng tính bằng mili giây. Độ chính xác của chúng là nền tảng cụ thể. Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được truyền vào phương thức tạo đối tượng, các thuộc tính sẽ là bigint, nếu không chúng sẽ là 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'];
Các thuộc tính
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 là các bigint giữ thời gian tương ứng tính bằng nano giây. Chúng chỉ xuất hiện khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được truyền vào phương thức tạo đối tượng. Độ chính xác của chúng là nền tảng cụ thểimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
203 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 là các đại diện thay thế đối tượng củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
05 trong các thời điểm khác nhau. Giá trịimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05 và số không được kết nối. Việc chỉ định một giá trị số mới hoặc thay đổi giá trịimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05 sẽ không được phản ánh trong biểu diễn thay thế tương ứngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Thời gian trong đối tượng stat có ngữ nghĩa sau
03 "Thời gian truy cập". Thời gian khi dữ liệu tệp được truy cập lần cuối. Được thay đổi bởi các cuộc gọi hệ thốngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
211import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 "Thời gian sửa đổi". Thời gian khi dữ liệu tệp được sửa đổi lần cuối. Được thay đổi bởi các cuộc gọi hệ thốngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 "Thay đổi thời gian". Thời gian khi trạng thái tệp được thay đổi lần cuối [sửa đổi dữ liệu inode]. Được thay đổi bởi các cuộc gọi hệ thốngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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,import * as fs from 'node:fs';
const fs = require['node:fs'];
02,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
26,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']; }];
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'];
229,import * as fs from 'node:fs';
const fs = require['node:fs'];
00,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
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 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 "Giờ sinh". Thời gian tạo tập tin. Đặt một lần khi tệp được tạo. Trên các hệ thống tệp không có sẵn thời gian sinh, thay vào đó, trường này có thể chứaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 [tức là dấu thời gian kỷ nguyên Uniximport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39]. This value may be greater thanimport * as fs from 'node:fs';
const fs = require['node:fs'];
03 orimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04 in this case. Trên Darwin và các biến thể FreeBSD khác, cũng được đặt nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
03 được đặt rõ ràng thành giá trị sớm hơn giá trị hiện tại củaimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
204 bằng lệnh gọi hệ thốngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
210import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trước nút. js 0. 12,
203 giữimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 trên hệ thống Windows. kể từ 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 không phải là "thời gian sáng tạo" và trên các hệ thống Unix, nó chưa bao giờ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
238#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các phiên bản của được tạo và trả về bằng cách sử dụng hàm
42Event.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05#import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi bộ mô tả tệp cơ bản của đã bị đóng
Biến cố.056#import * as fs from 'node:fs';
const fs = require['node:fs'];
Phát ra khi tệp của được mở
Biến cố.121#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phát ra khi đã sẵn sàng để được sử dụng
Cháy ngay sau
056import * as fs from 'node:fs';
const fs = require['node:fs'];
244#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng byte được ghi cho đến nay. Không bao gồm dữ liệu vẫn đang xếp hàng để ghi
245#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng
246. Tùy chọn chấp nhận một cuộc gọi lại sẽ được thực hiện sau khi đóngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
246import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn đến tệp mà luồng đang ghi vào như được chỉ định trong đối số đầu tiên của
42. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 được truyền dưới dạng chuỗi, thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 sẽ là chuỗi. Ifimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 , thenimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 will be aimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
254#import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Thuộc tính này là
97 nếu tệp cơ bản chưa được mở, tôi. e. trước khi sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được phát raimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trả về một đối tượng chứa các hằng số thường được sử dụng cho các hoạt động của hệ thống tệp
Hằng số FS#Các hằng số sau đây được xuất bởi
47 vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
46import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Không phải mọi hằng số sẽ có sẵn trên mọi hệ điều hành; . Đối với các ứng dụng di động, nên kiểm tra sự hiện diện của chúng trước khi sử dụng
Để sử dụng nhiều hơn một hằng số, hãy sử dụng toán tử bitwise OR
260import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Thí dụ
Hằng số truy cập tệp #Các hằng số sau được dùng làm tham số
48 được truyền choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
264ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
265Cờ cho biết tệp hiển thị với quy trình gọi. Điều này hữu ích để xác định xem một tệp có tồn tại hay không, nhưng không nói gì về quyền củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mặc định nếu không có chế độ nào được chỉ định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
267Cờ cho biết quá trình gọi có thể đọc tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
268Cờ chỉ ra rằng tệp có thể được ghi bởi quá trình gọi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
269Cờ chỉ ra rằng tệp có thể được thực thi bởi quy trình gọi. Điều này không ảnh hưởng đến Windows [sẽ hoạt động nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The definitions are also available on Windows
Hằng số sao chép tệp #Các hằng số sau đây được dùng với
271ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
272Nếu có, thao tác sao chép sẽ không thành công với lỗi nếu đường dẫn đích đã tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
273Nếu có, thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng cơ bản không hỗ trợ sao chép khi ghi, thì cơ chế sao chép dự phòng sẽ được sử dụng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
274Nếu có, thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng cơ bản không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành công với lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The definitions are also available on Windows
Các hằng số mở tệp#Các hằng số sau đây được dùng với
64ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
276Cờ cho biết mở tệp để truy cập chỉ đọc.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
277Flag indicating to open a file for write-only 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'];
278Cờ cho biết mở tệp để truy cập đọc-ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279Cờ cho biết để tạo tệp nếu nó chưa tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280Cờ cho biết rằng việc mở tệp sẽ không thành công nếu cờimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được đặt và tệp đã tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
282Cờ chỉ ra rằng nếu đường dẫn xác định một thiết bị đầu cuối, thì việc mở đường dẫn sẽ không khiến thiết bị đầu cuối đó trở thành thiết bị đầu cuối kiểm soát quy trình [nếu quy trình chưa có].import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283Cờ chỉ ra rằng nếu tệp tồn tại và là tệp thông thường và tệp được mở thành công để truy cập ghi, thì độ dài của tệp sẽ bị cắt ngắn thành 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'];
284Cờ cho biết dữ liệu sẽ được thêm vào cuối tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285Cờ chỉ ra rằng việc mở sẽ thất bại nếu đường dẫn không phải là một thư mục.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
286Cờ cho biết quyền truy cập đọc vào hệ thống tệp sẽ không còn dẫn đến cập nhật thông tinimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 được liên kết với tệp. Cờ này chỉ khả dụng trên hệ điều hành Linux.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
288Cờ chỉ ra rằng việc mở sẽ thất bại nếu đường dẫn là một liên kết tượng trưng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
289Cờ cho biết tệp được mở cho I/O được đồng bộ hóa với các thao tác ghi đang chờ tính toàn vẹn của tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
290Cờ cho biết tệp được mở cho I/O được đồng bộ hóa với các thao tác ghi đang chờ tính toàn vẹn của dữ liệu.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
291Cờ chỉ ra để mở chính liên kết tượng trưng chứ không phải tài nguyên mà nó đang trỏ tới.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
292Khi được đặt, một nỗ lực sẽ được thực hiện để giảm thiểu hiệu ứng bộ nhớ đệm của tệp 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'];
293Cờ cho biết mở tệp ở chế độ không chặn khi có thể.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
294Khi được đặt, ánh xạ tệp bộ nhớ được sử dụng để truy cập tệp. Cờ này chỉ khả dụng trên hệ điều hành Windows. On other operating systems, this flag is ignoredimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
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 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
294Hằng số loại tệp #import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các hằng số sau đây được dùng với thuộc tính
48 của đối tượng để xác định loại tệpConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 được sử dụng để trích xuất mã loại tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
305Hằng số loại tệp cho một tệp thông thường.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
306Hằng số loại tệp cho một thư mục.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
307Hằng số loại tệp cho tệp thiết bị định hướng ký tự.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
308Hằng số loại tệp cho tệp thiết bị hướng khối.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
309Hằng số loại tệp cho FIFO/đường ống.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
310Hằng số loại tệp cho một liên kết tượng trưng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
311Hằng số loại tệp cho ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
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 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
305Hằng số chế độ tệp #import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các hằng số sau đây được dùng với thuộc tính
48 của đối tượng để xác định quyền truy cập đối với một tệpConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
318Chế độ tệp cho biết chủ sở hữu có thể đọc, ghi và thực thi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
319Chế độ tệp cho biết chủ sở hữu có thể đọc được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
320Chế độ tệp cho biết chủ sở hữu có thể ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
321Chế độ tệp cho biết chủ sở hữu có thể thực thi được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
322Chế độ tệp cho biết có thể đọc, ghi và thực thi theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
323File mode indicating readable 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'];
324File mode indicating writable 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'];
325Chế độ tệp cho biết có thể thực thi theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
326Chế độ tệp cho biết người khác có thể đọc, ghi và thực thi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
327Chế độ tệp cho biết người khác có thể đọc được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
328Chế độ tệp cho biết người khác có thể ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
329Chế độ tệp cho biết người khác có thể thực thi đượcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
319 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
320import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ghi chú #
Thứ tự gọi lại và các hoạt động dựa trên lời hứa #
Bởi vì chúng được thực thi không đồng bộ bởi nhóm luồng bên dưới, nên không có thứ tự được đảm bảo khi sử dụng phương pháp gọi lại hoặc dựa trên lời hứa
Ví dụ: phần sau dễ bị lỗi vì thao tác
330 có thể hoàn thành trước thao tácimport * as fs from 'node:fs';
const fs = require['node:fs'];
333import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Điều quan trọng là phải sắp xếp đúng thứ tự các thao tác bằng cách đợi kết quả của thao tác này trước khi gọi thao tác kia
1import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Hoặc, khi sử dụng API gọi lại, hãy di chuyển lệnh gọi
330 vào lệnh gọi lại của hoạt độngimport * as fs from 'node:fs';
const fs = require['node:fs'];
333import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 }];
Đường dẫn tệp#
Hầu hết các hoạt động của
56 chấp nhận đường dẫn tệp có thể được chỉ định ở dạng chuỗi, a hoặc đối tượng bằng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54Đường dẫn chuỗi #import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đường dẫn chuỗi được hiểu là chuỗi ký tự UTF-8 xác định tên tệp tuyệt đối hoặc tương đối. Relative paths will be resolved relative to the current working directory as determined by calling
338import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ví dụ sử dụng đường dẫn tuyệt đối trên POSIX
Ví dụ sử dụng đường dẫn tương đối trên POSIX [liên quan đến
338]Đường dẫn URL tệp #import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối với hầu hết các hàm mô-đun
4, đối sốimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
12 có thể được truyền dưới dạng đối tượng bằng cách sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54import { 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 luôn là đường dẫn tuyệt đốiCân nhắc dành riêng cho nền tảng#import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trên Windows,
54 s với tên máy chủ chuyển đổi thành đường dẫn UNC, trong khiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s với ký tự ổ đĩa chuyển đổi thành đường dẫn tuyệt đối cục bộ.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s không có tên máy chủ và không có ký tự ổ đĩa sẽ dẫn đến lỗiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s với ký tự ổ đĩa phải sử dụngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
349 làm dấu phân cách ngay sau ký tự ổ đĩa. Sử dụng dấu phân cách khác sẽ dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên tất cả các nền tảng khác,
54 s có tên máy chủ không được hỗ trợ và sẽ gây ra lỗiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Một
54 có các ký tự gạch chéo được mã hóa sẽ dẫn đến lỗi trên tất cả các nền tảngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trên Windows,
54 s có dấu gạch chéo ngược được mã hóa sẽ dẫn đến lỗiĐường dẫn đệm #import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đường dẫn được chỉ định bằng cách sử dụng a chủ yếu hữu ích trên một số hệ điều hành POSIX coi đường dẫn tệp là chuỗi byte mờ. Trên các hệ thống như vậy, một đường dẫn tệp duy nhất có thể chứa các chuỗi con sử dụng nhiều mã hóa ký tự. Như với đường dẫn chuỗi, đường dẫn có thể là tương đối hoặc tuyệt đối
Ví dụ sử dụng đường dẫn tuyệt đối trên POSIX
Thư mục làm việc trên mỗi ổ đĩa trên Windows#Trên Windows, Nút. js tuân theo khái niệm thư mục làm việc trên mỗi ổ đĩa. Hành vi này có thể được quan sát thấy khi sử dụng đường dẫn ổ đĩa không có dấu gạch chéo ngược. Ví dụ:
353 có khả năng trả về một kết quả khác vớiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Để biết thêm thông tin, hãy xem trang MSDN nàyimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
File descriptors#
Trên các hệ thống POSIX, đối với mọi quy trình, kernel duy trì một bảng các tệp và tài nguyên hiện đang mở. Mỗi tệp đang mở được gán một mã định danh số đơn giản được gọi là bộ mô tả tệp. At the system-level, all file system operations use these file descriptors to identify and track each specific file. Các hệ thống Windows sử dụng một cơ chế khác nhưng tương tự về mặt khái niệm để theo dõi tài nguyên. Để đơn giản hóa mọi thứ cho người dùng, Node. js trừu tượng hóa sự khác biệt giữa các hệ điều hành và gán cho tất cả các tệp đang mở một bộ mô tả tệp số
Các phương thức
64 dựa trên gọi lại vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 đồng bộ mở một tệp và phân bổ một bộ mô tả tệp mới. Sau khi được phân bổ, bộ mô tả tệp có thể được sử dụng để đọc dữ liệu, ghi dữ liệu vào hoặc yêu cầu thông tin về tệpimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Hệ điều hành giới hạn số lượng bộ mô tả tệp có thể được mở tại bất kỳ thời điểm nào, do đó, điều quan trọng là phải đóng bộ mô tả khi hoàn thành các thao tác. Không làm như vậy sẽ dẫn đến rò rỉ bộ nhớ, cuối cùng sẽ khiến ứng dụng bị sập
Các API dựa trên lời hứa sử dụng một đối tượng thay cho bộ mô tả tệp số. Các đối tượng này được hệ thống quản lý tốt hơn đảm bảo tài nguyên không bị rò rỉ. Tuy nhiên, chúng vẫn được yêu cầu đóng lại khi hoạt động hoàn tất
Sử dụng threadpool #
Tất cả API hệ thống tệp gọi lại và dựa trên lời hứa [ngoại trừ
357] đều sử dụng nhóm luồng của libuv. Điều này có thể có ý nghĩa hiệu suất đáng ngạc nhiên và tiêu cực đối với một số ứng dụng. Xem tài liệuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
358 để biết thêm thông tinimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cờ hệ thống tập tin #
Các cờ sau có sẵn ở bất cứ nơi nào tùy chọn
359 lấy một chuỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Open file for appending. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mở tệp để đọc và nối thêm. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mở tệp để nối thêm ở chế độ đồng bộ. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mở tệp để đọc và nối thêm ở chế độ đồng bộ. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mở tệp để đọc. Một ngoại lệ xảy ra nếu tệp không tồn tạiimport { 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']; }];
369. Open file for reading and writing. Một ngoại lệ xảy ra nếu tệp không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Mở tệp để đọc và ghi ở chế độ đồng bộ. Hướng dẫn hệ điều hành bỏ qua bộ đệm ẩn của hệ thống tệp cục bộimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
This is primarily useful for opening files on NFS mounts as it allows skipping the potentially stale local cache. Nó có tác động rất thực đến hiệu năng I/O nên không nên sử dụng cờ này trừ khi cần thiết
Điều này không biến
64 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 thành cuộc gọi chặn đồng bộ. Nếu muốn hoạt động đồng bộ, nên sử dụng một cái gì đó nhưimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
93import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
374. Mở tệp để viết. Tệp được tạo [nếu không tồn tại] hoặc bị cắt bớt [nếu tồn tại]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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. The file is created [if it does not exist] or truncated [if it 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'];
378. Likeimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 but fails if the path existsimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 can also be a number as documented byimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
58; commonly used constants are available fromimport { 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']; }];
47. On Windows, flags are translated to their equivalent ones where applicable, e. g.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
277 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, orimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 toimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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, as accepted byimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
387import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
The exclusive flag
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 flag inimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
58] causes the operation to return an error if the path already exists. On POSIX, if the path is a symbolic link, usingimport { 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']; }];
280 returns an error even if the link is to a path that does not exist. Cờ độc quyền có thể không hoạt động với hệ thống tệp mạngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
On Linux, positional writes don't 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
Sửa đổi một tệp thay vì thay thế nó có thể yêu cầu tùy chọn
359 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 thay vì mặc định làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
374import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Hành vi của một số cờ là dành riêng cho nền tảng. Như vậy, việc mở một thư mục trên macOS và Linux bằng cờ
363, như trong ví dụ bên dưới, sẽ trả về lỗi. Ngược lại, trên Windows và FreeBSD, một bộ mô tả tệp hoặc mộtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
02 sẽ được trả vềimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Trên Windows, mở một tệp ẩn hiện có bằng cờ
374 [thông quaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [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 { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
76 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
03] sẽ không thành công vớiimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
528. Các tệp ẩn hiện có có thể được mở để ghi bằng cờimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
369import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
JavaScript có thể mở tệp cục bộ không?
Trình duyệt web [và JavaScript] chỉ có thể truy cập các tệp cục bộ khi có sự cho phép của người dùng . Để chuẩn hóa quyền truy cập tệp từ trình duyệt, W3C đã xuất bản API tệp HTML5 vào năm 2014. Nó xác định cách truy cập và tải lên các tệp cục bộ bằng các đối tượng tệp trong các ứng dụng web.Bạn có thể đọc một tệp bằng JavaScript không?
Để đọc tệp, sử dụng FileReader , cho phép bạn đọc nội dung của đối tượng Tệp vào bộ nhớ. Bạn có thể hướng dẫn FileReader đọc tệp dưới dạng bộ đệm mảng, URL dữ liệu hoặc văn bản.Có xử lý tệp trong JavaScript không?
Xử lý tệp trong JavaScript là một kỹ thuật trong đó tệp được viết ở định dạng html bằng cách sử dụng CSS có thể được gọi bằng cách sử dụng tệp html bên ngoài hoặc sử dụng. tệp js trỏ đến tệp html đó . Thao tác xử lý tệp trong JavaScript bao gồm mở tệp, đóng tệp, Cập nhật dữ liệu trong tệp.