Check if a CreateWriteStream is writable in Node.js using Javascript

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const isWritableStream = val =>
val !== null &&
typeof val === 'object' &&
typeof val.pipe === 'function' &&
typeof val._write === 'function' &&
typeof val._writableState === 'object';
const fs = require('fs');
isWritableStream(fs.createWriteStream('test.txt')); // true
const isWritableStream = val => val !== null && typeof val === 'object' && typeof val.pipe === 'function' && typeof val._write === 'function' && typeof val._writableState === 'object'; const fs = require('fs'); isWritableStream(fs.createWriteStream('test.txt')); // true
const isWritableStream = val =>
  val !== null &&
  typeof val === 'object' &&
  typeof val.pipe === 'function' &&
  typeof val._write === 'function' &&
  typeof val._writableState === 'object';

const fs = require('fs');

isWritableStream(fs.createWriteStream('test.txt')); // true

Tags: CreateWriteStream, filesystem, fs, WriteStream, Node.js, Node, Javascript, Typescript

CC BY 4.0 no changes made – 30 Seconds of Code