最終更新:2022-09-14 (水) 10:39:30 (593d)  

Node.js/fs
Top / Node.js / fs

https://nodejs.org/api/fs.html

クラス

種類

Promise API

  • JavaScript/await
    import { unlink } from 'node:fs/promises';
    
    try {
      await unlink('/tmp/hello');
      console.log('successfully deleted /tmp/hello');
    } catch (error) {
      console.error('there was an error:', error.message);
    }

Callback API

  • 非同期処理
    import { unlink } from 'node:fs';
    
    unlink('/tmp/hello', (err) => {
      if (err) throw err;
      console.log('successfully deleted /tmp/hello');
    });

Synchronous API

  • 同期処理
    import { unlinkSync } from 'node:fs';
    
    try {
      unlinkSync('/tmp/hello');
      console.log('successfully deleted /tmp/hello');
    } catch (err) {
      // handle the error
    }

関数

  • fs.access?(path[, mode], callback)
  • fs.accessSync?(path[, mode])
  • fs.appendFile?(file, data[, options], callback)
  • fs.appendFileSync?(file, data[, options])
  • fs.chmod?(path, mode, callback)
  • fs.chmodSync?(path, mode)
  • fs.chown?(path, uid, gid, callback)
  • fs.chownSync?(path, uid, gid)
  • fs.close?(fd, callback)
  • fs.closeSync?(fd)
  • fs.constants?
  • fs.copyFile?(src, dest[, flags], callback)
  • fs.copyFileSync?(src, dest[, flags])
  • fs.createReadStream(path[, options])
  • fs.createWriteStream?(path[, options])
  • fs.exists?(path, callback)
  • fs.existsSync?(path)
  • fs.fchmod?(fd, mode, callback)
  • fs.fchmodSync?(fd, mode)
  • fs.fchown?(fd, uid, gid, callback)
  • fs.fchownSync?(fd, uid, gid)
  • fs.fdatasync?(fd, callback)
  • fs.fdatasyncSync?(fd)
  • fs.fstat?(fd, callback)
  • fs.fstatSync?(fd)
  • fs.fsync?(fd, callback)
  • fs.fsyncSync?(fd)
  • fs.ftruncate?(fd[, len], callback)
  • fs.ftruncateSync?(fd[, len])
  • fs.futimes?(fd, atime, mtime, callback)
  • fs.futimesSync?(fd, atime, mtime)
  • fs.lchmod?(path, mode, callback)
  • fs.lchmodSync?(path, mode)
  • fs.lchown?(path, uid, gid, callback)
  • fs.lchownSync?(path, uid, gid)
  • fs.link?(existingPath, newPath, callback)
  • fs.linkSync?(existingPath, newPath)
  • fs.lstat?(path, callback)
  • fs.lstatSync?(path)
  • fs.mkdir?(path[, mode], callback)
  • fs.mkdirSync?(path[, mode])
  • fs.mkdtemp?(prefix[, options], callback)
  • fs.mkdtempSync?(prefix[, options])
  • fs.open?(path, flags[, mode], callback)
  • fs.openSync?(path, flags[, mode])
  • fs.read?(fd, buffer, offset, length, position, callback)
  • fs.readdir?(path[, options], callback)
  • fs.readdirSync?(path[, options])
  • fs.readFile(path[, options], callback)
  • fs.readFileSync(path[, options])
  • fs.readlink?(path[, options], callback)
  • fs.readlinkSync?(path[, options])
  • fs.readSync?(fd, buffer, offset, length, position)
  • fs.realpath?(path[, options], callback)
  • fs.realpath?.native(path[, options], callback)
  • fs.realpathSync?(path[, options])
  • fs.realpathSync?.native(path[, options])
  • fs.rename?(oldPath, newPath, callback)
  • fs.renameSync(oldPath, newPath)
  • fs.rmdir?(path, callback)
  • fs.rmdirSync?(path)
  • fs.stat?(path, callback)
  • fs.statSync(path)
  • fs.symlink?(target, path[, type], callback)
  • fs.symlinkSync?(target, path[, type])
  • fs.truncate?(path[, len], callback)
  • fs.truncateSync?(path[, len])
  • fs.unlink?(path, callback)
  • fs.unlinkSync?(path)
  • fs.unwatchFile?(filename[, listener])
  • fs.utimes?(path, atime, mtime, callback)
  • fs.utimesSync?(path, atime, mtime)
  • fs.watch?(filename[, options][, listener])
  • fs.watchFile?(filename[, options], listener)
  • fs.write?(fd, buffer[, offset[, length[, position]]], callback)
  • fs.write?(fd, string[, position[, encoding]], callback)
  • fs.writeFile?(file, data[, options], callback)
  • fs.writeFileSync?(file, data[, options])
  • fs.writeSync?(fd, buffer[, offset[, length[, position]]])
  • fs.writeSync?(fd, string[, position[, encoding]])