Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Clarify fs.symlink() usage #29700

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3249,22 +3249,32 @@ changes:
* `callback` {Function}
* `err` {Error}

Asynchronous symlink(2). No arguments other than a possible exception are given
to the completion callback. The `type` argument is only available on Windows
and ignored on other platforms. It can be set to `'dir'`, `'file'`, or
`'junction'`. If the `type` argument is not set, Node will autodetect `target`
type and use `'file'` or `'dir'`. If the `target` does not exist, `'file'` will
be used. Windows junction points require the destination path to be absolute.
When using `'junction'`, the `target` argument will automatically be normalized
to absolute path.
Asynchronous symlink(2) which creates the link called `path` pointing to
`target`. No arguments other than a possible exception are given to the
completion callback.

Here is an example below:
The `type` argument is only available on Windows and ignored on other platforms.
It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
not set, Node will autodetect `target` type and use `'file'` or `'dir'`. If the
`target` does not exist, `'file'` will be used. Windows junction points require
the destination path to be absolute. When using `'junction'`, the `target`
argument will automatically be normalized to absolute path.

Relative targets are relative to the link’s parent directory.

```js
fs.symlink('./foo', './new-port', callback);
fs.symlink('./mew', './example/mewtwo', callback);
```

It creates a symbolic link named "new-port" that points to "foo".
The above example creates a symbolic link `mewtwo` in the `example` which points
to `mew` in the same directory:

```bash
$ tree example/
example/
├── mew
└── mewtwo -> ./mew
```

## fs.symlinkSync(target, path[, type])
<!-- YAML
Expand Down