fs.symlink(target, path[, type], callback)


创建名为 path 指向 target 的链接。除了可能的异常之外,没有为完成回调提供任何参数。

¥Creates the link called path pointing to target. No arguments other than a possible exception are given to the completion callback.

有关更多详细信息,请参阅 POSIX symlink(2) 文档。

¥See the POSIX symlink(2) documentation for more details.

type 参数仅在 Windows 上可用,在其他平台上被忽略。可以设置为 'dir''file''junction'。如果 type 参数是 null,Node.js 将自动检测 target 类型并使用 'file''dir'。如果 target 不存在,将使用 'file'。Windows 交接点要求目标路径是绝对路径。使用 'junction' 时,target 参数将自动规范化为绝对路径。NTFS 卷上的连接点只能指向目录。

¥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 null, Node.js 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. Junction points on NTFS volumes can only point to directories.

相对目标是相对于链接的父目录。

¥Relative targets are relative to the link's parent directory.

import { symlink } from 'node:fs';

symlink('./mew', './mewtwo', callback); 

上面的示例创建了符号链接 mewtwo,其指向同一目录中的 mew

¥The above example creates a symbolic link mewtwo which points to mew in the same directory:

$ tree .
.
├── mew
└── mewtwo -> ./mew