Filesystem
fs/promises.unlink()
Removes a file name or symbolic link, not a directory. Handle missing paths according to the operation contract. Tested on Node.js 22.16.0. Example output (one line per entry): ["ENOENT"].
Formal Syntax & Structure
nodejs syntaxnodejs
unlink(path)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | URL | Owned entry. |
Return Value
Promise<void>
Completes after removing entry.
Working Example
Example Snippetnodejs
import * as fs from 'node:fs/promises';import { constants } from 'node:fs';import { join } from 'node:path';import { tmpdir } from 'node:os';const dir = await fs.mkdtemp(join(tmpdir(), 'bytemind-'));try { const p = join(dir, 'book.txt'); await fs.writeFile(p, 'catalog'); await fs.unlink(p); try { await fs.readFile(p); } catch (e) { console.log(e.code); }}finally { await fs.rm(dir, { recursive: true, force: true });}