NODEJS DOCS
GLOBAL-OBJECTS
Name
Description
Example
Output
globalDescription: Objek global Node.js (seperti window di browser).
Example:
console.log(global)
Output: <ref *1> Object [global] ...
globalObjek global Node.js (seperti window di browser).
console.log(global)
<ref *1> Object [global] ...
globalThisDescription: Referensi standar ke objek global (Node.js & browser).
Example:
globalThis.setTimeout === setTimeout
Output: true
globalThisReferensi standar ke objek global (Node.js & browser).
globalThis.setTimeout === setTimeout
true
__dirnameDescription: Path direktori file saat ini (CommonJS only).
Example:
console.log(__dirname)
Output: /home/user/project/src
__dirnamePath direktori file saat ini (CommonJS only).
console.log(__dirname)
/home/user/project/src
__filenameDescription: Path lengkap file saat ini (CommonJS only).
Example:
console.log(__filename)
Output: /home/user/project/src/app.js
__filenamePath lengkap file saat ini (CommonJS only).
console.log(__filename)
/home/user/project/src/app.js
processDescription: Objek proses Node.js (env, argv, exit, dll).
Example:
console.log(process.pid)
Output: 12345
processObjek proses Node.js (env, argv, exit, dll).
console.log(process.pid)
12345
process.argvDescription: Array argumen command line.
Example:
node app.js arg1 arg2
Output: ['node', 'app.js', 'arg1', 'arg2']
process.argvArray argumen command line.
node app.js arg1 arg2
['node', 'app.js', 'arg1', 'arg2']
process.envDescription: Environment variables.
Example:
process.env.NODE_ENV
Output: 'production'
process.envEnvironment variables.
process.env.NODE_ENV
'production'
process.cwd()Description: Current working directory.
Example:
process.cwd()
Output: /home/user/project
process.cwd()Current working directory.
process.cwd()
/home/user/project
process.exit(code)Description: Keluar dari proses dengan kode.
Example:
process.exit(0)
Output: Keluar sukses
process.exit(code)Keluar dari proses dengan kode.
process.exit(0)
Keluar sukses
process.nextTick(cb)Description: Jalankan callback di next tick event loop.
Example:
process.nextTick(() => console.log('next'))Output: next (sebelum I/O)
process.nextTick(cb)Jalankan callback di next tick event loop.
process.nextTick(() => console.log('next'))next (sebelum I/O)
process.memoryUsage()Description: Info penggunaan memori.
Example:
process.memoryUsage()
Output: { rss: ..., heapTotal: ..., heapUsed: ... }
process.memoryUsage()Info penggunaan memori.
process.memoryUsage()
{ rss: ..., heapTotal: ..., heapUsed: ... }
process.uptime()Description: Uptime proses dalam detik.
Example:
process.uptime()
Output: 123.456
process.uptime()Uptime proses dalam detik.
process.uptime()
123.456
process.platformDescription: Platform OS (linux, darwin, win32).
Example:
process.platform
Output: 'linux'
process.platformPlatform OS (linux, darwin, win32).
process.platform
'linux'
process.versionDescription: Versi Node.js.
Example:
process.version
Output: 'v20.10.0'
process.versionVersi Node.js.
process.version
'v20.10.0'
BufferDescription: Menangani data biner.
Example:
Buffer.from('hello')Output: <Buffer 68 65 6c 6c 6f>
BufferMenangani data biner.
Buffer.from('hello')<Buffer 68 65 6c 6c 6f>
URLDescription: Parsing & manipulasi URL (WHATWG API).
Example:
new URL('https://example.com/path?q=1')Output: URL object
URLParsing & manipulasi URL (WHATWG API).
new URL('https://example.com/path?q=1')URL object
URLSearchParamsDescription: Parsing query string.
Example:
new URLSearchParams('q=hello&page=1')Output: URLSearchParams { 'q' => 'hello', 'page' => '1' }
URLSearchParamsParsing query string.
new URLSearchParams('q=hello&page=1')URLSearchParams { 'q' => 'hello', 'page' => '1' }
TextEncoderDescription: Encode string ke Uint8Array.
Example:
new TextEncoder().encode('hi')Output: Uint8Array [104, 105]
TextEncoderEncode string ke Uint8Array.
new TextEncoder().encode('hi')Uint8Array [104, 105]
TextDecoderDescription: Decode Uint8Array ke string.
Example:
new TextDecoder().decode(buffer)
Output: 'hi'
TextDecoderDecode Uint8Array ke string.
new TextDecoder().decode(buffer)
'hi'
setTimeout(cb, delay)Description: Jalankan callback setelah delay ms.
Example:
setTimeout(() => {}, 1000)Output: Timeout object
setTimeout(cb, delay)Jalankan callback setelah delay ms.
setTimeout(() => {}, 1000)Timeout object
setInterval(cb, delay)Description: Jalankan callback berulang tiap delay ms.
Example:
setInterval(() => {}, 1000)Output: Interval object
setInterval(cb, delay)Jalankan callback berulang tiap delay ms.
setInterval(() => {}, 1000)Interval object
setImmediate(cb)Description: Jalankan callback di fase check event loop.
Example:
setImmediate(() => console.log('immediate'))Output: immediate
setImmediate(cb)Jalankan callback di fase check event loop.
setImmediate(() => console.log('immediate'))immediate
clearTimeout(id)Description: Hentikan timeout.
Example:
clearTimeout(id)
Output: Dibatalkan
clearTimeout(id)Hentikan timeout.
clearTimeout(id)
Dibatalkan
clearInterval(id)Description: Hentikan interval.
Example:
clearInterval(id)
Output: Dibatalkan
clearInterval(id)Hentikan interval.
clearInterval(id)
Dibatalkan
clearImmediate(id)Description: Hentikan immediate.
Example:
clearImmediate(id)
Output: Dibatalkan
clearImmediate(id)Hentikan immediate.
clearImmediate(id)
Dibatalkan
FS
Name
Description
Example
Output
fs.readFile(path, cb)Description: Baca file secara asynchronous.
Example:
fs.readFile('/path/file.txt', 'utf8', (err, data) => {})Output: Isi file
fs.readFile(path, cb)Baca file secara asynchronous.
fs.readFile('/path/file.txt', 'utf8', (err, data) => {})Isi file
fs.readFileSync(path)Description: Baca file secara synchronous.
Example:
const data = fs.readFileSync('/path/file.txt', 'utf8')Output: Isi file
fs.readFileSync(path)Baca file secara synchronous.
const data = fs.readFileSync('/path/file.txt', 'utf8')Isi file
fs.writeFile(path, data, cb)Description: Tulis file (overwrite).
Example:
fs.writeFile('/path/file.txt', 'Hello', (err) => {})Output: File tertulis
fs.writeFile(path, data, cb)Tulis file (overwrite).
fs.writeFile('/path/file.txt', 'Hello', (err) => {})File tertulis
fs.writeFileSync(path, data)Description: Tulis file synchronous.
Example:
fs.writeFileSync('/path/file.txt', 'Hello')Output: File tertulis
fs.writeFileSync(path, data)Tulis file synchronous.
fs.writeFileSync('/path/file.txt', 'Hello')File tertulis
fs.appendFile(path, data, cb)Description: Tambah data ke akhir file.
Example:
fs.appendFile('/path/file.txt', 'World', (err) => {})Output: Data ditambahkan
fs.appendFile(path, data, cb)Tambah data ke akhir file.
fs.appendFile('/path/file.txt', 'World', (err) => {})Data ditambahkan
fs.unlink(path, cb)Description: Hapus file.
Example:
fs.unlink('/path/file.txt', (err) => {})Output: File dihapus
fs.unlink(path, cb)Hapus file.
fs.unlink('/path/file.txt', (err) => {})File dihapus
fs.existsSync(path)Description: Cek apakah path ada (sync).
Example:
fs.existsSync('/path/file.txt')Output: true / false
fs.existsSync(path)Cek apakah path ada (sync).
fs.existsSync('/path/file.txt')true / false
fs.mkdir(path, cb)Description: Buat folder.
Example:
fs.mkdir('/path/new-folder', (err) => {})Output: Folder dibuat
fs.mkdir(path, cb)Buat folder.
fs.mkdir('/path/new-folder', (err) => {})Folder dibuat
fs.mkdirSync(path, { recursive: true })Description: Buat folder recursive.
Example:
fs.mkdirSync('/a/b/c', { recursive: true })Output: Semua folder dibuat
fs.mkdirSync(path, { recursive: true })Buat folder recursive.
fs.mkdirSync('/a/b/c', { recursive: true })Semua folder dibuat
fs.rmdir(path, cb)Description: Hapus folder kosong.
Example:
fs.rmdir('/path/folder', (err) => {})Output: Folder dihapus
fs.rmdir(path, cb)Hapus folder kosong.
fs.rmdir('/path/folder', (err) => {})Folder dihapus
fs.rm(path, { recursive: true }, cb)Description: Hapus folder beserta isinya (Node 14+).
Example:
fs.rm('/path/folder', { recursive: true, force: true }, (err) => {})Output: Folder & isi dihapus
fs.rm(path, { recursive: true }, cb)Hapus folder beserta isinya (Node 14+).
fs.rm('/path/folder', { recursive: true, force: true }, (err) => {})Folder & isi dihapus
fs.readdir(path, cb)Description: Baca isi folder.
Example:
fs.readdir('/path', (err, files) => {})Output: ['file1.txt', 'file2.js']
fs.readdir(path, cb)Baca isi folder.
fs.readdir('/path', (err, files) => {})['file1.txt', 'file2.js']
fs.stat(path, cb)Description: Info file/folder (size, modified, dll).
Example:
fs.stat('/path/file.txt', (err, stats) => {})Output: Stats { size: 123, ... }
fs.stat(path, cb)Info file/folder (size, modified, dll).
fs.stat('/path/file.txt', (err, stats) => {})Stats { size: 123, ... }
fs.copyFile(src, dest, cb)Description: Copy file.
Example:
fs.copyFile('src.txt', 'dest.txt', (err) => {})Output: File dicopy
fs.copyFile(src, dest, cb)Copy file.
fs.copyFile('src.txt', 'dest.txt', (err) => {})File dicopy
fs.rename(old, new, cb)Description: Rename / pindahkan file.
Example:
fs.rename('old.txt', 'new.txt', (err) => {})Output: File direname
fs.rename(old, new, cb)Rename / pindahkan file.
fs.rename('old.txt', 'new.txt', (err) => {})File direname
fs.watch(path, cb)Description: Pantau perubahan file/folder.
Example:
fs.watch('/path', (event, filename) => {})Output: 'change' 'file.txt'
fs.watch(path, cb)Pantau perubahan file/folder.
fs.watch('/path', (event, filename) => {})'change' 'file.txt'
fs.createReadStream(path)Description: Stream baca file (untuk file besar).
Example:
fs.createReadStream('large.mp4').pipe(res)Output: Readable stream
fs.createReadStream(path)Stream baca file (untuk file besar).
fs.createReadStream('large.mp4').pipe(res)Readable stream
fs.createWriteStream(path)Description: Stream tulis file.
Example:
fs.createWriteStream('output.txt').write('data')Output: Writable stream
fs.createWriteStream(path)Stream tulis file.
fs.createWriteStream('output.txt').write('data')Writable stream
fs/promisesDescription: Versi Promise dari semua fs method.
Example:
import fs from 'fs/promises'; await fs.readFile('file.txt')Output: Promise-based
fs/promisesVersi Promise dari semua fs method.
import fs from 'fs/promises'; await fs.readFile('file.txt')Promise-based
PATH
Name
Description
Example
Output
path.join(...paths)Description: Gabung path secara aman.
Example:
path.join('/home', 'user', 'file.txt')Output: /home/user/file.txt
path.join(...paths)Gabung path secara aman.
path.join('/home', 'user', 'file.txt')/home/user/file.txt
path.resolve(...paths)Description: Resolve ke absolute path.
Example:
path.resolve('src', 'app.js')Output: /home/user/project/src/app.js
path.resolve(...paths)Resolve ke absolute path.
path.resolve('src', 'app.js')/home/user/project/src/app.js
path.basename(p)Description: Nama file dari path.
Example:
path.basename('/home/file.txt')Output: 'file.txt'
path.basename(p)Nama file dari path.
path.basename('/home/file.txt')'file.txt'
path.basename(p, ext)Description: Nama file tanpa ekstensi.
Example:
path.basename('/home/file.txt', '.txt')Output: 'file'
path.basename(p, ext)Nama file tanpa ekstensi.
path.basename('/home/file.txt', '.txt')'file'
path.dirname(p)Description: Nama folder dari path.
Example:
path.dirname('/home/file.txt')Output: '/home'
path.dirname(p)Nama folder dari path.
path.dirname('/home/file.txt')'/home'
path.extname(p)Description: Ekstensi file.
Example:
path.extname('index.html')Output: '.html'
path.extname(p)Ekstensi file.
path.extname('index.html')'.html'
path.parse(p)Description: Parse path ke object.
Example:
path.parse('/home/file.txt')Output: { root: '/', dir: '/home', base: 'file.txt', ext: '.txt', name: 'file' }
path.parse(p)Parse path ke object.
path.parse('/home/file.txt'){ root: '/', dir: '/home', base: 'file.txt', ext: '.txt', name: 'file' }
path.format(obj)Description: Format object ke path string.
Example:
path.format({ dir: '/home', base: 'file.txt' })Output: '/home/file.txt'
path.format(obj)Format object ke path string.
path.format({ dir: '/home', base: 'file.txt' })'/home/file.txt'
path.isAbsolute(p)Description: Cek absolute path.
Example:
path.isAbsolute('/home')Output: true
path.isAbsolute(p)Cek absolute path.
path.isAbsolute('/home')true
path.relative(from, to)Description: Relative path dari from ke to.
Example:
path.relative('/a/b', '/a/c/file.txt')Output: '../c/file.txt'
path.relative(from, to)Relative path dari from ke to.
path.relative('/a/b', '/a/c/file.txt')'../c/file.txt'
path.normalize(p)Description: Normalisasi path (buang .. dan .).
Example:
path.normalize('/a//b/../c')Output: '/a/c'
path.normalize(p)Normalisasi path (buang .. dan .).
path.normalize('/a//b/../c')'/a/c'
path.sepDescription: Separator path OS (/ atau \).
Example:
path.sep
Output: '/'
path.sepSeparator path OS (/ atau \).
path.sep
'/'
path.delimiterDescription: Delimiter PATH OS (: atau ;).
Example:
path.delimiter
Output: ':'
path.delimiterDelimiter PATH OS (: atau ;).
path.delimiter
':'
OS
Name
Description
Example
Output
os.platform()Description: Platform OS.
Example:
os.platform()
Output: 'linux' | 'darwin' | 'win32'
os.platform()Platform OS.
os.platform()
'linux' | 'darwin' | 'win32'
os.arch()Description: Arsitektur CPU.
Example:
os.arch()
Output: 'x64' | 'arm64'
os.arch()Arsitektur CPU.
os.arch()
'x64' | 'arm64'
os.cpus()Description: Info CPU cores.
Example:
os.cpus()
Output: [{ model: '...', speed: 3200 }]
os.cpus()Info CPU cores.
os.cpus()
[{ model: '...', speed: 3200 }]
os.totalmem()Description: Total RAM dalam bytes.
Example:
os.totalmem()
Output: 17179869184
os.totalmem()Total RAM dalam bytes.
os.totalmem()
17179869184
os.freemem()Description: RAM kosong dalam bytes.
Example:
os.freemem()
Output: 8589934592
os.freemem()RAM kosong dalam bytes.
os.freemem()
8589934592
os.homedir()Description: Home directory user.
Example:
os.homedir()
Output: '/home/user'
os.homedir()Home directory user.
os.homedir()
'/home/user'
os.tmpdir()Description: Temp directory.
Example:
os.tmpdir()
Output: '/tmp'
os.tmpdir()Temp directory.
os.tmpdir()
'/tmp'
os.hostname()Description: Hostname komputer.
Example:
os.hostname()
Output: 'my-laptop'
os.hostname()Hostname komputer.
os.hostname()
'my-laptop'
os.networkInterfaces()Description: Info network interfaces.
Example:
os.networkInterfaces()
Output: { lo: [...], eth0: [...] }
os.networkInterfaces()Info network interfaces.
os.networkInterfaces()
{ lo: [...], eth0: [...] }
os.uptime()Description: Uptime sistem dalam detik.
Example:
os.uptime()
Output: 3600
os.uptime()Uptime sistem dalam detik.
os.uptime()
3600
os.EOLDescription: End of line karakter OS.
Example:
os.EOL
Output: '\n' | '\r\n'
os.EOLEnd of line karakter OS.
os.EOL
'\n' | '\r\n'
HTTP
Name
Description
Example
Output
http.createServer(cb)Description: Buat HTTP server.
Example:
http.createServer((req, res) => { res.end('Hello') }).listen(3000)Output: Server di port 3000
http.createServer(cb)Buat HTTP server.
http.createServer((req, res) => { res.end('Hello') }).listen(3000)Server di port 3000
res.writeHead(code, headers)Description: Set status code & header response.
Example:
res.writeHead(200, { 'Content-Type': 'application/json' })Output: Header terkirim
res.writeHead(code, headers)Set status code & header response.
res.writeHead(200, { 'Content-Type': 'application/json' })Header terkirim
res.end(data)Description: Akhiri response (kirim data opsional).
Example:
res.end(JSON.stringify({ ok: true }))Output: Response selesai
res.end(data)Akhiri response (kirim data opsional).
res.end(JSON.stringify({ ok: true }))Response selesai
res.write(data)Description: Kirim chunk data (streaming).
Example:
res.write('chunk1'); res.write('chunk2'); res.end()Output: Data terkirim
res.write(data)Kirim chunk data (streaming).
res.write('chunk1'); res.write('chunk2'); res.end()Data terkirim
req.urlDescription: URL request.
Example:
req.url
Output: '/api/users?id=1'
req.urlURL request.
req.url
'/api/users?id=1'
req.methodDescription: HTTP method request.
Example:
req.method
Output: 'GET' | 'POST' | ...
req.methodHTTP method request.
req.method
'GET' | 'POST' | ...
req.headersDescription: Headers request.
Example:
req.headers['content-type']
Output: 'application/json'
req.headersHeaders request.
req.headers['content-type']
'application/json'
req.on('data', cb)Description: Terima body request (stream).
Example:
req.on('data', chunk => { body += chunk })Output: Chunk data
req.on('data', cb)Terima body request (stream).
req.on('data', chunk => { body += chunk })Chunk data
req.on('end', cb)Description: Body request selesai diterima.
Example:
req.on('end', () => { console.log(body) })Output: Body lengkap
req.on('end', cb)Body request selesai diterima.
req.on('end', () => { console.log(body) })Body lengkap
http.get(url, cb)Description: HTTP GET request sederhana.
Example:
http.get('http://api.example.com', (res) => {})Output: Response
http.get(url, cb)HTTP GET request sederhana.
http.get('http://api.example.com', (res) => {})Response
http.request(options, cb)Description: Custom HTTP request.
Example:
const req = http.request({ hostname: 'api.example.com', method: 'POST' }, cb); req.write(data); req.end()Output: Request terkirim
http.request(options, cb)Custom HTTP request.
const req = http.request({ hostname: 'api.example.com', method: 'POST' }, cb); req.write(data); req.end()Request terkirim
HTTPS
Name
Description
Example
Output
https.createServer(options, cb)Description: Buat HTTPS server.
Example:
https.createServer({ key, cert }, cb).listen(443)Output: Server HTTPS
https.createServer(options, cb)Buat HTTPS server.
https.createServer({ key, cert }, cb).listen(443)Server HTTPS
https.get(url, cb)Description: HTTPS GET request.
Example:
https.get('https://api.example.com', res => {})Output: Response
https.get(url, cb)HTTPS GET request.
https.get('https://api.example.com', res => {})Response
EVENTS
Name
Description
Example
Output
new EventEmitter()Description: Buat event emitter.
Example:
const ee = new EventEmitter()
Output: EventEmitter
new EventEmitter()Buat event emitter.
const ee = new EventEmitter()
EventEmitter
.on(event, listener)Description: Daftarkan listener event.
Example:
ee.on('data', (payload) => {})Output: Listener terdaftar
.on(event, listener)Daftarkan listener event.
ee.on('data', (payload) => {})Listener terdaftar
.once(event, listener)Description: Listener sekali jalan.
Example:
ee.once('ready', () => {})Output: Sekali saja
.once(event, listener)Listener sekali jalan.
ee.once('ready', () => {})Sekali saja
.emit(event, ...args)Description: Trigger event.
Example:
ee.emit('data', { id: 1 })Output: Event triggered
.emit(event, ...args)Trigger event.
ee.emit('data', { id: 1 })Event triggered
.off(event, listener)Description: Hapus listener event.
Example:
ee.off('data', handler)Output: Listener dihapus
.off(event, listener)Hapus listener event.
ee.off('data', handler)Listener dihapus
.removeAllListeners(event)Description: Hapus semua listener event.
Example:
ee.removeAllListeners('data')Output: Semua listener dihapus
.removeAllListeners(event)Hapus semua listener event.
ee.removeAllListeners('data')Semua listener dihapus
.listenerCount(event)Description: Jumlah listener event.
Example:
ee.listenerCount('data')Output: 3
.listenerCount(event)Jumlah listener event.
ee.listenerCount('data')3
.eventNames()Description: Array nama event yang terdaftar.
Example:
ee.eventNames()
Output: ['data', 'error']
.eventNames()Array nama event yang terdaftar.
ee.eventNames()
['data', 'error']
.setMaxListeners(n)Description: Set maksimum listener (default 10).
Example:
ee.setMaxListeners(20)
Output: Limit 20
.setMaxListeners(n)Set maksimum listener (default 10).
ee.setMaxListeners(20)
Limit 20
STREAM
Name
Description
Example
Output
ReadableDescription: Stream yang bisa dibaca.
Example:
new Readable({ read(size) {} })Output: Readable stream
ReadableStream yang bisa dibaca.
new Readable({ read(size) {} })Readable stream
WritableDescription: Stream yang bisa ditulis.
Example:
new Writable({ write(chunk, enc, cb) {} })Output: Writable stream
WritableStream yang bisa ditulis.
new Writable({ write(chunk, enc, cb) {} })Writable stream
TransformDescription: Stream baca-tulis (modifikasi data).
Example:
new Transform({ transform(chunk, enc, cb) {} })Output: Transform stream
TransformStream baca-tulis (modifikasi data).
new Transform({ transform(chunk, enc, cb) {} })Transform stream
DuplexDescription: Stream baca & tulis (independen).
Example:
new Duplex({ read() {}, write() {} })Output: Duplex stream
DuplexStream baca & tulis (independen).
new Duplex({ read() {}, write() {} })Duplex stream
stream.pipeline(...streams, cb)Description: Pipe stream dengan error handling otomatis.
Example:
pipeline(readable, transform, writable, (err) => {})Output: Pipeline selesai
stream.pipeline(...streams, cb)Pipe stream dengan error handling otomatis.
pipeline(readable, transform, writable, (err) => {})Pipeline selesai
stream.finished(stream, cb)Description: Callback saat stream selesai/error.
Example:
finished(writable, (err) => { console.log('done') })Output: Stream selesai
stream.finished(stream, cb)Callback saat stream selesai/error.
finished(writable, (err) => { console.log('done') })Stream selesai
stream.Readable.from(iterable)Description: Buat readable stream dari iterable.
Example:
Readable.from(['a', 'b', 'c'])
Output: Readable stream
stream.Readable.from(iterable)Buat readable stream dari iterable.
Readable.from(['a', 'b', 'c'])
Readable stream
CRYPTO
Name
Description
Example
Output
crypto.randomBytes(size)Description: Generate random bytes.
Example:
crypto.randomBytes(16).toString('hex')Output: 'a1b2c3d4...'
crypto.randomBytes(size)Generate random bytes.
crypto.randomBytes(16).toString('hex')'a1b2c3d4...'
crypto.randomUUID()Description: Generate random UUID v4.
Example:
crypto.randomUUID()
Output: '550e8400-e29b-...'
crypto.randomUUID()Generate random UUID v4.
crypto.randomUUID()
'550e8400-e29b-...'
crypto.createHash(algorithm)Description: Buat hash (sha256, md5, dll).
Example:
crypto.createHash('sha256').update('data').digest('hex')Output: Hash hex
crypto.createHash(algorithm)Buat hash (sha256, md5, dll).
crypto.createHash('sha256').update('data').digest('hex')Hash hex
crypto.createHmac(algorithm, key)Description: Buat HMAC.
Example:
crypto.createHmac('sha256', 'secret').update('data').digest('hex')Output: HMAC hex
crypto.createHmac(algorithm, key)Buat HMAC.
crypto.createHmac('sha256', 'secret').update('data').digest('hex')HMAC hex
crypto.createCipheriv(algo, key, iv)Description: Enkripsi data.
Example:
crypto.createCipheriv('aes-256-cbc', key, iv)Output: Cipher
crypto.createCipheriv(algo, key, iv)Enkripsi data.
crypto.createCipheriv('aes-256-cbc', key, iv)Cipher
crypto.createDecipheriv(algo, key, iv)Description: Dekripsi data.
Example:
crypto.createDecipheriv('aes-256-cbc', key, iv)Output: Decipher
crypto.createDecipheriv(algo, key, iv)Dekripsi data.
crypto.createDecipheriv('aes-256-cbc', key, iv)Decipher
crypto.pbkdf2(password, salt, iter, len, algo, cb)Description: Hash password dengan salt.
Example:
crypto.pbkdf2('pass', 'salt', 100000, 64, 'sha512', (err, key) => {})Output: Derived key
crypto.pbkdf2(password, salt, iter, len, algo, cb)Hash password dengan salt.
crypto.pbkdf2('pass', 'salt', 100000, 64, 'sha512', (err, key) => {})Derived key
crypto.timingSafeEqual(a, b)Description: Bandingkan buffer aman dari timing attack.
Example:
crypto.timingSafeEqual(buf1, buf2)
Output: true / false
crypto.timingSafeEqual(a, b)Bandingkan buffer aman dari timing attack.
crypto.timingSafeEqual(buf1, buf2)
true / false
CHILD-PROCESS
Name
Description
Example
Output
child_process.exec(cmd, cb)Description: Jalankan command shell.
Example:
exec('ls -la', (err, stdout, stderr) => {})Output: stdout
child_process.exec(cmd, cb)Jalankan command shell.
exec('ls -la', (err, stdout, stderr) => {})stdout
child_process.execSync(cmd)Description: Jalankan command synchronous.
Example:
execSync('ls -la')Output: Buffer stdout
child_process.execSync(cmd)Jalankan command synchronous.
execSync('ls -la')Buffer stdout
child_process.spawn(cmd, args)Description: Jalankan proses (stream).
Example:
spawn('ls', ['-la'])Output: ChildProcess
child_process.spawn(cmd, args)Jalankan proses (stream).
spawn('ls', ['-la'])ChildProcess
child_process.fork(module)Description: Jalankan module Node.js di proses baru.
Example:
fork('./worker.js')Output: ChildProcess
child_process.fork(module)Jalankan module Node.js di proses baru.
fork('./worker.js')ChildProcess
child_process.execFile(file, args, cb)Description: Jalankan file tanpa shell.
Example:
execFile('node', ['--version'], cb)Output: stdout
child_process.execFile(file, args, cb)Jalankan file tanpa shell.
execFile('node', ['--version'], cb)stdout
UTIL
Name
Description
Example
Output
util.promisify(fn)Description: Ubah callback-based function ke Promise.
Example:
const readFile = util.promisify(fs.readFile)
Output: Async function
util.promisify(fn)Ubah callback-based function ke Promise.
const readFile = util.promisify(fs.readFile)
Async function
util.types.isPromise(val)Description: Cek apakah value adalah Promise.
Example:
util.types.isPromise(Promise.resolve())
Output: true
util.types.isPromise(val)Cek apakah value adalah Promise.
util.types.isPromise(Promise.resolve())
true
util.types.isDate(val)Description: Cek apakah value adalah Date.
Example:
util.types.isDate(new Date())
Output: true
util.types.isDate(val)Cek apakah value adalah Date.
util.types.isDate(new Date())
true
util.format(format, ...args)Description: Format string seperti printf.
Example:
util.format('%s %d', 'hello', 42)Output: 'hello 42'
util.format(format, ...args)Format string seperti printf.
util.format('%s %d', 'hello', 42)'hello 42'
util.inspect(obj, options)Description: String representasi objek (debug).
Example:
util.inspect({ a: 1 }, { colors: true, depth: null })Output: String berwarna
util.inspect(obj, options)String representasi objek (debug).
util.inspect({ a: 1 }, { colors: true, depth: null })String berwarna
util.deprecate(fn, msg)Description: Tandai fungsi sebagai deprecated.
Example:
const oldFn = util.deprecate(fn, 'Use newFn instead')
Output: Deprecation warning
util.deprecate(fn, msg)Tandai fungsi sebagai deprecated.
const oldFn = util.deprecate(fn, 'Use newFn instead')
Deprecation warning
util.callbackify(asyncFn)Description: Ubah async function ke callback-based.
Example:
util.callbackify(asyncFn)((err, result) => {})Output: Callback
util.callbackify(asyncFn)Ubah async function ke callback-based.
util.callbackify(asyncFn)((err, result) => {})Callback
ASSERT
Name
Description
Example
Output
assert.ok(value, msg)Description: Assert value truthy.
Example:
assert.ok(true, 'harus true')
Output: Tidak error
assert.ok(value, msg)Assert value truthy.
assert.ok(true, 'harus true')
Tidak error
assert.strictEqual(a, b)Description: Assert a === b.
Example:
assert.strictEqual(1, 1)
Output: Tidak error
assert.strictEqual(a, b)Assert a === b.
assert.strictEqual(1, 1)
Tidak error
assert.deepStrictEqual(a, b)Description: Assert deep equal (objek).
Example:
assert.deepStrictEqual({ a: 1 }, { a: 1 })Output: Tidak error
assert.deepStrictEqual(a, b)Assert deep equal (objek).
assert.deepStrictEqual({ a: 1 }, { a: 1 })Tidak error
assert.throws(fn)Description: Assert function throw error.
Example:
assert.throws(() => { throw new Error('fail') })Output: Tidak error
assert.throws(fn)Assert function throw error.
assert.throws(() => { throw new Error('fail') })Tidak error
assert.rejects(asyncFn)Description: Assert async function reject.
Example:
await assert.rejects(() => Promise.reject('err'))Output: Tidak error
assert.rejects(asyncFn)Assert async function reject.
await assert.rejects(() => Promise.reject('err'))Tidak error
assert.fail(msg)Description: Selalu gagal.
Example:
assert.fail('harus gagal')Output: AssertionError
assert.fail(msg)Selalu gagal.
assert.fail('harus gagal')AssertionError
NPM-PNPM
Name
Description
Example
Output
npm initDescription: Inisialisasi package.json.
Example:
npm init -y
Output: package.json dibuat
npm initInisialisasi package.json.
npm init -y
package.json dibuat
npm installDescription: Install semua dependency dari package.json.
Example:
npm install
Output: node_modules/
npm installInstall semua dependency dari package.json.
npm install
node_modules/
npm install <pkg>Description: Install package (dependencies).
Example:
npm install express
Output: Package terinstall
npm install <pkg>Install package (dependencies).
npm install express
Package terinstall
npm install -D <pkg>Description: Install sebagai devDependencies.
Example:
npm install -D typescript
Output: Dev dependency
npm install -D <pkg>Install sebagai devDependencies.
npm install -D typescript
Dev dependency
npm install -g <pkg>Description: Install global.
Example:
npm install -g nodemon
Output: Global
npm install -g <pkg>Install global.
npm install -g nodemon
Global
npm uninstall <pkg>Description: Hapus package.
Example:
npm uninstall express
Output: Package dihapus
npm uninstall <pkg>Hapus package.
npm uninstall express
Package dihapus
npm updateDescription: Update semua package.
Example:
npm update
Output: Package diupdate
npm updateUpdate semua package.
npm update
Package diupdate
npm run <script>Description: Jalankan script dari package.json.
Example:
npm run dev
Output: Script berjalan
npm run <script>Jalankan script dari package.json.
npm run dev
Script berjalan
npx <command>Description: Jalankan package tanpa install.
Example:
npx create-next-app@latest
Output: Package berjalan
npx <command>Jalankan package tanpa install.
npx create-next-app@latest
Package berjalan
pnpm installDescription: Install dengan pnpm (lebih cepat).
Example:
pnpm install
Output: node_modules/
pnpm installInstall dengan pnpm (lebih cepat).
pnpm install
node_modules/
pnpm add <pkg>Description: Install package dengan pnpm.
Example:
pnpm add react
Output: Package terinstall
pnpm add <pkg>Install package dengan pnpm.
pnpm add react
Package terinstall
npm listDescription: Lihat daftar package terinstall.
Example:
npm list --depth=0
Output: Daftar package
npm listLihat daftar package terinstall.
npm list --depth=0
Daftar package
npm outdatedDescription: Cek package yang outdated.
Example:
npm outdated
Output: Daftar outdated
npm outdatedCek package yang outdated.
npm outdated
Daftar outdated
npm auditDescription: Cek vulnerability.
Example:
npm audit
Output: Laporan security
npm auditCek vulnerability.
npm audit
Laporan security
npm audit fixDescription: Auto-fix vulnerability.
Example:
npm audit fix
Output: Vulnerability diperbaiki
npm audit fixAuto-fix vulnerability.
npm audit fix
Vulnerability diperbaiki
MODULE-SYSTEM
Name
Description
Example
Output
require(module)Description: Import module (CommonJS).
Example:
const fs = require('fs')Output: Module
require(module)Import module (CommonJS).
const fs = require('fs')Module
module.exportsDescription: Export dari file (CommonJS).
Example:
module.exports = { fn }Output: Ter-export
module.exportsExport dari file (CommonJS).
module.exports = { fn }Ter-export
exports.nameDescription: Export named (CommonJS).
Example:
exports.myFn = fn
Output: Ter-export
exports.nameExport named (CommonJS).
exports.myFn = fn
Ter-export
import * as name from 'module'Description: Import semua (ESM).
Example:
import * as fs from 'fs'
Output: Namespace
import * as name from 'module'Import semua (ESM).
import * as fs from 'fs'
Namespace
import { name } from 'module'Description: Import named (ESM).
Example:
import { readFile } from 'fs'Output: Named import
import { name } from 'module'Import named (ESM).
import { readFile } from 'fs'Named import
import defaultExport from 'module'Description: Import default (ESM).
Example:
import express from 'express'
Output: Default import
import defaultExport from 'module'Import default (ESM).
import express from 'express'
Default import
export defaultDescription: Export default (ESM).
Example:
export default function fn() {}Output: Default export
export defaultExport default (ESM).
export default function fn() {}Default export
export { name }Description: Export named (ESM).
Example:
export { fn1, fn2 }Output: Named export
export { name }Export named (ESM).
export { fn1, fn2 }Named export
export const name = ...Description: Export inline (ESM).
Example:
export const PORT = 3000
Output: Inline export
export const name = ...Export inline (ESM).
export const PORT = 3000
Inline export
import.meta.urlDescription: URL modul saat ini (ESM).
Example:
import.meta.url
Output: 'file:///path/to/file.js'
import.meta.urlURL modul saat ini (ESM).
import.meta.url
'file:///path/to/file.js'
import.meta.dirnameDescription: Dirname modul (ESM, Node 21+).
Example:
import.meta.dirname
Output: '/path/to'
import.meta.dirnameDirname modul (ESM, Node 21+).
import.meta.dirname
'/path/to'
PACKAGE-JSON
Name
Description
Example
Output
"name"Description: Nama package (lowercase, no space).
Example:
"name": "my-app"
Output: Nama
"name"Nama package (lowercase, no space).
"name": "my-app"
Nama
"version"Description: Versi semantik (1.0.0).
Example:
"version": "1.0.0"
Output: Versi
"version"Versi semantik (1.0.0).
"version": "1.0.0"
Versi
"main"Description: Entry point (CommonJS).
Example:
"main": "index.js"
Output: Entry CJS
"main"Entry point (CommonJS).
"main": "index.js"
Entry CJS
"module"Description: Entry point (ESM).
Example:
"module": "index.mjs"
Output: Entry ESM
"module"Entry point (ESM).
"module": "index.mjs"
Entry ESM
"type"Description: "module" untuk ESM, "commonjs" untuk CJS.
Example:
"type": "module"
Output: ESM
"type""module" untuk ESM, "commonjs" untuk CJS.
"type": "module"
ESM
"scripts"Description: Custom script (npm run ...).
Example:
"scripts": { "dev": "node app.js" }Output: npm run dev
"scripts"Custom script (npm run ...).
"scripts": { "dev": "node app.js" }npm run dev
"dependencies"Description: Package untuk production.
Example:
"dependencies": { "express": "^4.18.0" }Output: Production deps
"dependencies"Package untuk production.
"dependencies": { "express": "^4.18.0" }Production deps
"devDependencies"Description: Package untuk development.
Example:
"devDependencies": { "typescript": "^5.0.0" }Output: Dev deps
"devDependencies"Package untuk development.
"devDependencies": { "typescript": "^5.0.0" }Dev deps
"peerDependencies"Description: Dependency yang harus diinstall user.
Example:
"peerDependencies": { "react": "^18.0.0" }Output: Peer deps
"peerDependencies"Dependency yang harus diinstall user.
"peerDependencies": { "react": "^18.0.0" }Peer deps
"engines"Description: Versi Node.js minimal.
Example:
"engines": { "node": ">=18.0.0" }Output: Node >=18
"engines"Versi Node.js minimal.
"engines": { "node": ">=18.0.0" }Node >=18
"exports"Description: Package exports map (modern).
Example:
"exports": { ".": "./index.js", "./utils": "./utils.js" }Output: Export map
"exports"Package exports map (modern).
"exports": { ".": "./index.js", "./utils": "./utils.js" }Export map