DEV Community

LG
LG

Posted on

Two common ways to destruct modules is Node.js

Destructuring in CJS

const {stdin: input, stdout: output} = require('process');

// Example exploiting Readline
const rl_cjs = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
Enter fullscreen mode Exit fullscreen mode

Destructuring in ESM

import { stdin as input, stdout as output } from 'process';

// Example exploiting Readline
const rl_esm = readline.createInterface({ input, output });
Enter fullscreen mode Exit fullscreen mode

If any typos found and (or) suggestions could be made, please leave it in the comment section below . Thank you and see you in the next one !

Top comments (0)