How to use the symlinkSync function from fs

Find comprehensive JavaScript fs.symlinkSync code examples handpicked from public code repositorys.

84
85
86
87
88
89
90
91
92
93
exports.rmdir = co.promisify(fs.rmdir);
exports.rmdirSync = fs.rmdirSync;
exports.stat = co.promisify(fs.stat);
exports.statSync = fs.statSync;
exports.symlink = co.promisify(fs.symlink);
exports.symlinkSync = fs.symlinkSync;
exports.truncate = co.promisify(fs.truncate);
exports.truncateSync = fs.truncateSync;
exports.unlink = co.promisify(fs.unlink);
exports.unlinkSync = fs.unlinkSync;
fork icon22
star icon45
watch icon26

120
121
122
123
124
125
126
127
128
129
130
131
132


// lchmod
if (fs.lchmod) {
  const link = path.join(common.tmpDir, 'symbolic-link');


  fs.symlinkSync(file2, link);


  fs.lchmod(link, mode_async, common.mustCall((err) => {
    assert.ifError(err);

fork icon16
star icon65
watch icon0

252
253
254
255
256
257
258
259
260
261
262
263
  };


  fs.symlink(existingFile, existingFile2, common.mustCall(validateError));


  assert.throws(
    () => fs.symlinkSync(existingFile, existingFile2),
    validateError
  );
}

fork icon42
star icon19
watch icon0

257
258
259
260
261
262
263
264
265
266
267
}


function readlink() {
  const fs = require('fs');
  fs.writeFileSync('fs29.txt', '123', 'utf8');
  fs.symlinkSync('fs29.txt', 'fs30.txt');
  fs.readlink('fs30.txt', () => {
    fs.unlinkSync('fs29.txt');
    fs.unlinkSync('fs30.txt');
  });
fork icon0
star icon0
watch icon0

+ 2 other calls in file

108
109
110
111
112
113
114
115
116
117
118
119
}


if (!common.isWindows) {
  const filename = getFilename();
  const link = `${filename}-link`;
  fs.symlinkSync(filename, link);
  runSyncTest(fs.lstatSync, link);
}


{
fork icon0
star icon0
watch icon0

+ 2 other calls in file

65
66
67
68
69
70
71
72
73
74

if (fs.lchmod) {
  const link = path.join(tmpdir.path, `lchmod-src-${suffix}`);
  const file = path.join(tmpdir.path, `lchmod-dest-${suffix}`);
  fs.writeFileSync(file, 'test', 'utf-8');
  fs.symlinkSync(file, link);

  fs.lchmod(link, input, common.mustSucceed(() => {
    assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode);
  }));
fork icon0
star icon0
watch icon0

+ 9 other calls in file

23
24
25
26
27
28
29
30
31
32
33
34
if (common.canCreateSymLink()) {
  const sourceFile = path.resolve(tmpdir.path, 'test-readlink');
  const linkFile = path.resolve(tmpdir.path, 'test-readlink-link');


  fs.writeFileSync(sourceFile, '');
  fs.symlinkSync(sourceFile, linkFile);


  fs.readlink(linkFile, options, common.mustCall(errHandler));
  fs.readlinkSync(linkFile, options);
}
fork icon0
star icon0
watch icon0