Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const path = require('path'); const os = require('os'); const crypto = require('crypto'); const util = require('util'); const events = require('events'); // path — cross-platform file paths console.log(path.basename('/usr/local/bin/node')); // 'node' console.log(path.extname('index.html')); // '.html' console.log(path.join('src', 'utils', 'helper.js')); // os — system information console.log(os.hostname()); // machine name console.log(os.cpus().length); // number of CPU cores console.log(os.freemem()); // free RAM in bytes // crypto — hashing const hash = crypto.createHash('sha256') .update('my secret password') .digest('hex'); console.log(hash); // events — EventEmitter const emitter = new events.EventEmitter(); emitter.on('data', (msg) => console.log('Received:', msg)); emitter.emit('data', 'Hello from EventEmitter'); // util — promisify a callback function const fs = require('fs'); const readFileAsync = util.promisify(fs.readFile);
Result
Open