Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > FileSystem > createHardLink

Creates a hard link. The link target must be a file, not a folder. Behind the scenes it uses fs.linkSync().

Signature:

static createHardLink(options: IFileSystemCreateLinkOptions): void;

Parameters

ParameterTypeDescription
optionsIFileSystemCreateLinkOptions

Returns:

void

Remarks

For security reasons, Windows operating systems by default require administrator elevation to create symbolic links. As a result, on Windows it's generally recommended for Node.js tools to use hard links (for files) or NTFS directory junctions (for folders), since regular users are allowed to create them. Hard links and junctions are less vulnerable to symlink attacks because they cannot reference a network share, and their target must exist at the time of link creation. Non-Windows operating systems generally don't restrict symlink creation, and as such are more vulnerable to symlink attacks. Note that Windows can be configured to permit regular users to create symlinks, for example by enabling Windows 10 "developer mode."

A hard link requires the link source and target to both be located on same disk volume; if not, use a symbolic link instead.