lt;blockquotegt;lt;pgt;lt;emgt;quot;Để xây dựng ứng dụng thông minh, đôi khi bạn cần biết nó đang chạy trên hệ điều hành nào, có bao nhiêu CPU, bao nhiêu RAM và thư mục Home ở đâu. Module lt;code inline=quot;quot;gt;oslt;/codegt; giúp Node.js làm được điều đó.quot;lt;/emgt;lt;/pgt;lt;/blockquotegt;lt;hr /gt;lt;h1gt;🎯 Mục tiêu bài họclt;/h1gt;lt;pgt;Sau bài này bạn sẽ:lt;/pgt;lt;ulgt;lt;ligt;lt;pgt;Hiểu module lt;stronggt;oslt;/stronggt; là gì.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Lấy thông tin hệ điều hành.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Kiểm tra CPU, RAM và kiến trúc máy.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Biết thư mục Home, Temp.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Phân biệt các hàm thường dùng trong module lt;code inline=quot;quot;gt;oslt;/codegt;.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Ứng dụng lt;code inline=quot;quot;gt;oslt;/codegt; trong các dự án thực tế.lt;/pgt;lt;div class=quot;separatorquot; style=quot;clear: both; text-align: center;quot;gt;lt;a href=quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij_JbfZgGxhDHlhvFJqvEXm5b4dp8i1yciKlWioDTQFyWhx7jMvRjEhTsNMWbvOO2XAoX1UR19-mHko5iXLBOXwwLffgDEQLjBs_yFQT9xab5jU_soEfG5vzHGNIETRVVC1um1vVmiEL0nN8hA6Rna0SsBh2Wbr7rbRQI1z4mXu1Itac8pU6NMQFEoq4k/s1536/bai8.pngquot; style=quot;margin-left: 1em; margin-right: 1em;quot;gt;lt;img border=quot;0quot; data-original-height=quot;1024quot; data-original-width=quot;1536quot; height=quot;213quot; src=quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij_JbfZgGxhDHlhvFJqvEXm5b4dp8i1yciKlWioDTQFyWhx7jMvRjEhTsNMWbvOO2XAoX1UR19-mHko5iXLBOXwwLffgDEQLjBs_yFQT9xab5jU_soEfG5vzHGNIETRVVC1um1vVmiEL0nN8hA6Rna0SsBh2Wbr7rbRQI1z4mXu1Itac8pU6NMQFEoq4k/s320/bai8.pngquot; width=quot;320quot; /gt;lt;/agt;lt;spangt;lt;a name=#39;more#39;gt;lt;/agt;lt;/spangt;lt;/divgt;lt;pgt;lt;/pgt;lt;/ligt;lt;/ulgt;lt;hr /gt;lt;h1gt;Module os là gì?lt;/h1gt;lt;pgt;lt;code inline=quot;quot;gt;oslt;/codegt; (Operating System) là module có sẵn của Node.js.lt;/pgt;lt;pgt;Không cần cài đặt.lt;/pgt;lt;pgt;Import:lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import os from quot;node:osquot;;
lt;/codegt;lt;/pregt;lt;pgt;Hoặc theo từng hàm (lúc gọi k có chữ os)lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import {
cpus,
totalmem
} from quot;node:osquot;;
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.platform()lt;/h1gt;lt;pgt;Cho biết hệ điều hành đang chạy.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import os from quot;node:osquot;;
console.log(
os.platform()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pgt;Windowslt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;win32
lt;/codegt;lt;/pregt;lt;pgt;Linuxlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;linux
lt;/codegt;lt;/pregt;lt;pgt;macOSlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;darwin
lt;/codegt;lt;/pregt;lt;blockquotegt;lt;pgt;lt;stronggt;Lưu ý:lt;/stronggt; Giá trị lt;code inline=quot;quot;gt;win32lt;/codegt; vẫn được sử dụng cho Windows 64-bit để đảm bảo tính tương thích ngược.lt;/pgt;lt;/blockquotegt;lt;hr /gt;lt;h1gt;os.arch()lt;/h1gt;lt;pgt;Kiến trúc CPU.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import os from quot;node:osquot;;
console.log(
os.arch()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;x64
lt;/codegt;lt;/pregt;lt;pgt;Hoặclt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;arm64
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.hostname()lt;/h1gt;lt;pgt;Tên máy tính.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.hostname()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;DESKTOP-ABC123
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.type()lt;/h1gt;lt;pgt;Loại hệ điều hành.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.type()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pgt;Windowslt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Windows_NT
lt;/codegt;lt;/pregt;lt;pgt;Linuxlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Linux
lt;/codegt;lt;/pregt;lt;pgt;macOSlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Darwin
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.release()lt;/h1gt;lt;pgt;Phiên bản hệ điều hành.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.release()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;10.0.26100
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.version()lt;/h1gt;lt;pgt;Thông tin phiên bản chi tiết hơn.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.version()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Windows 11 Pro
lt;/codegt;lt;/pregt;lt;pgt;(Chuỗi trả về phụ thuộc vào hệ điều hành.)lt;/pgt;lt;hr /gt;lt;h1gt;os.cpus()lt;/h1gt;lt;pgt;Thông tin CPU.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import os from quot;node:osquot;;
console.log(
os.cpus()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;[
{
model: quot;...quot;,
speed: 3200
}
]
lt;/codegt;lt;/pregt;lt;hr /gt;lt;pgt;Đếm số lõi CPUlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.cpus().length
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;8
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.availableParallelism()lt;/h1gt;lt;pgt;Đây là cách hiện đại để biết số luồng xử lý khả dụng.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.availableParallelism()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;8
lt;/codegt;lt;/pregt;lt;blockquotegt;lt;pgt;Trong các phiên bản Node.js mới, lt;code inline=quot;quot;gt;os.availableParallelism()lt;/codegt; được khuyến nghị thay cho việc dùng lt;code inline=quot;quot;gt;os.cpus().lengthlt;/codegt; khi cần xác định mức độ song song phù hợp.lt;/pgt;lt;/blockquotegt;lt;hr /gt;lt;h1gt;os.totalmem()lt;/h1gt;lt;pgt;Dung lượng RAM.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.totalmem()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;17071734784
lt;/codegt;lt;/pregt;lt;pgt;Đổi sang GBlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;const ram =
os.totalmem() /
1024 /
1024 /
1024;
console.log(
ram.toFixed(2)
);
lt;/codegt;lt;/pregt;lt;pgt;↓lt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;15.90 GB
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.freemem()lt;/h1gt;lt;pgt;RAM còn trống.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.freemem()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;8478232576
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.homedir()lt;/h1gt;lt;pgt;Thư mục Home.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.homedir()
);
lt;/codegt;lt;/pregt;lt;pgt;Windowslt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;C:\Users\Admin
lt;/codegt;lt;/pregt;lt;pgt;Linuxlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;/home/admin
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.tmpdir()lt;/h1gt;lt;pgt;Thư mục tạm.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.tmpdir()
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pgt;Windowslt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;C:\Users\Admin\AppData\Local\Temp
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.uptime()lt;/h1gt;lt;pgt;Thời gian máy đã hoạt động.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.uptime()
);
lt;/codegt;lt;/pregt;lt;pgt;↓lt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;86400
lt;/codegt;lt;/pregt;lt;pgt;Nghĩa làlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;86400 giây
lt;/codegt;lt;/pregt;lt;pgt;Đổi sang giờlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;const hours =
os.uptime() /
60 /
60;
console.log(
hours.toFixed(1)
);
lt;/codegt;lt;/pregt;lt;pgt;↓lt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;24.0 giờ
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.userInfo()lt;/h1gt;lt;pgt;Thông tin người dùng.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(JSON.stringify(os.userInfo(), null, 2));
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;{
username:#39;admin#39;,
shell:#39;cmd#39;
}
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;os.networkInterfaces()lt;/h1gt;lt;pgt;Thông tin mạng.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
JSON.stringify(os.networkInterfaces(), null, 2)
);
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Ethernet
Wi-Fi
IPv4
IPv6
lt;/codegt;lt;/pregt;lt;pgt;Thông tin này thường được dùng trong các công cụ quản trị hoặc chẩn đoán hệ thống.lt;/pgt;lt;hr /gt;lt;h1gt;os.EOLlt;/h1gt;lt;pgt;Ký tự xuống dòng của hệ điều hành.lt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.EOL
);
lt;/codegt;lt;/pregt;lt;pgt;Windowslt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;\r\n
lt;/codegt;lt;/pregt;lt;pgt;Linux/macOSlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;\n
lt;/codegt;lt;/pregt;lt;pgt;Ví dụlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import fs from quot;node:fsquot;;
import os from quot;node:osquot;;
fs.writeFileSync(
quot;log.txtquot;,
quot;Dong 1quot; +
os.EOL +
quot;Dong 2quot;
);
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;Ví dụ thực tếlt;/h1gt;lt;pgt;Hiển thị thông tin hệ thốnglt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;import os from quot;node:osquot;;
console.log(quot;Platform:quot;, os.platform());
console.log(quot;CPU:quot;, os.availableParallelism());
console.log(
quot;RAM:quot;,
(
os.totalmem()/1024/1024/1024
).toFixed(2),
quot;GBquot;
);
lt;/codegt;lt;/pregt;lt;pgt;Kết quảlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;Platform: win32
CPU: 8
RAM: 15.90 GB
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h1gt;Khi nào dùng module os?lt;/h1gt;lt;pgt;Rất hữu ích trong:lt;/pgt;lt;ulgt;lt;ligt;lt;pgt;Kiểm tra môi trường chạy.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Hiển thị thông tin máy chủ.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Công cụ CLI.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Dashboard quản trị.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Monitoring.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Docker.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;VPS.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;DevOps.lt;/pgt;lt;/ligt;lt;/ulgt;lt;hr /gt;lt;h1gt;Những lỗi thường gặplt;/h1gt;lt;h2gt;Nhầm platform()lt;/h2gt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;if(os.platform()==quot;windowsquot;)
lt;/codegt;lt;/pregt;lt;pgt;Sai.lt;/pgt;lt;pgt;Đúng làlt;/pgt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;if(os.platform()==quot;win32quot;)
lt;/codegt;lt;/pregt;lt;hr /gt;lt;h2gt;Không đổi đơn vị RAMlt;/h2gt;lt;pregt;lt;code class=quot;language-javascriptquot;gt;console.log(
os.totalmem()
);
lt;/codegt;lt;/pregt;lt;pgt;Kết quảlt;/pgt;lt;pregt;lt;code class=quot;language-textquot;gt;17071734784
lt;/codegt;lt;/pregt;lt;pgt;Đây là lt;stronggt;bytelt;/stronggt;, không phải GB.lt;/pgt;lt;hr /gt;lt;h2gt;Dùng cpus().length để tính hiệu nănglt;/h2gt;lt;pgt;lt;code inline=quot;quot;gt;os.cpus().lengthlt;/codegt; cho biết số lõi logic, nhưng không phản ánh đầy đủ khả năng xử lý của hệ thống. Trong các ứng dụng hiện đại, nên ưu tiên lt;code inline=quot;quot;gt;os.availableParallelism()lt;/codegt; khi cần xác định số luồng làm việc phù hợp.lt;/pgt;lt;hr /gt;lt;h1gt;Bảng tổng hợp các hàm thường dùnglt;/h1gt;lt;tablegt;lt;theadgt;lt;trgt;lt;thgt;Hàmlt;/thgt;lt;thgt;Ý nghĩalt;/thgt;lt;/trgt;lt;/theadgt;lt;tbodygt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;platform()lt;/codegt;lt;/tdgt;lt;tdgt;Hệ điều hànhlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;arch()lt;/codegt;lt;/tdgt;lt;tdgt;Kiến trúc CPUlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;hostname()lt;/codegt;lt;/tdgt;lt;tdgt;Tên máylt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;type()lt;/codegt;lt;/tdgt;lt;tdgt;Loại hệ điều hànhlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;release()lt;/codegt;lt;/tdgt;lt;tdgt;Phiên bản kernel/HĐHlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;version()lt;/codegt;lt;/tdgt;lt;tdgt;Phiên bản chi tiếtlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;cpus()lt;/codegt;lt;/tdgt;lt;tdgt;Thông tin CPUlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;availableParallelism()lt;/codegt;lt;/tdgt;lt;tdgt;Số luồng xử lý khả dụnglt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;totalmem()lt;/codegt;lt;/tdgt;lt;tdgt;Tổng RAMlt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;freemem()lt;/codegt;lt;/tdgt;lt;tdgt;RAM còn trốnglt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;homedir()lt;/codegt;lt;/tdgt;lt;tdgt;Thư mục Homelt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;tmpdir()lt;/codegt;lt;/tdgt;lt;tdgt;Thư mục Templt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;uptime()lt;/codegt;lt;/tdgt;lt;tdgt;Thời gian hoạt độnglt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;userInfo()lt;/codegt;lt;/tdgt;lt;tdgt;Người dùng hiện tạilt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;networkInterfaces()lt;/codegt;lt;/tdgt;lt;tdgt;Thông tin mạnglt;/tdgt;lt;/trgt;lt;trgt;lt;tdgt;lt;code inline=quot;quot;gt;EOLlt;/codegt;lt;/tdgt;lt;tdgt;Ký tự xuống dònglt;/tdgt;lt;/trgt;lt;/tbodygt;lt;/tablegt;lt;hr /gt;lt;h1gt;Tổng kếtlt;/h1gt;lt;pgt;Module lt;stronggt;oslt;/stronggt; giúp Node.js truy cập thông tin về hệ điều hành và phần cứng của máy đang chạy ứng dụng. Với các API như lt;code inline=quot;quot;gt;platform()lt;/codegt;, lt;code inline=quot;quot;gt;availableParallelism()lt;/codegt;, lt;code inline=quot;quot;gt;totalmem()lt;/codegt; hay lt;code inline=quot;quot;gt;homedir()lt;/codegt;, bạn có thể xây dựng các chương trình thích ứng với nhiều môi trường khác nhau, đồng thời hỗ trợ giám sát và quản trị hệ thống hiệu quả.lt;/pgt;lt;pgt;Đây là một module nền tảng thường được sử dụng trong các công cụ CLI, ứng dụng máy chủ, Docker, VPS và các hệ thống giám sát.lt;/pgt;
lt;pregt;lt;codegt;import os from quot;node:osquot;;
const user = os.userInfo();
console.log(`
Platform : ${os.platform()}
Arch : ${os.arch()}
Hostname : ${os.hostname()}
Type : ${os.type()}
Release : ${os.release()}
Version : ${os.version()}
CPU Model: ${os.cpus()[0].model}
CPU Speed: ${os.cpus()[0].speed} MHz
CPUs : ${os.cpus().length}
Số luồng : ${os.availableParallelism()}
RAM : ${(os.totalmem() / 1024 ** 3).toFixed(2)} GB
RAM trống: ${(os.freemem() / 1024 ** 3).toFixed(2)} GB
Home Dir : ${os.homedir()}
Temp Dir : ${os.tmpdir()}
Hoạt động: ${(os.uptime() / 3600).toFixed(2)} giờ
Username : ${user.username}
UID : ${user.uid}
GID : ${user.gid}
Home : ${user.homedir}
Shell : ${user.shell}
Network : ${JSON.stringify(os.networkInterfaces(), null, 2)}
`);
lt;/codegt;lt;/pregt;
lt;hr /gt;lt;h1gt;Bài tiếp theolt;/h1gt;lt;pgt;👉 lt;stronggt;Bài 09 — Eventslt;/stronggt;lt;/pgt;lt;pgt;Bạn sẽ học:lt;/pgt;lt;ulgt;lt;ligt;lt;pgt;Event là gì.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;lt;code inline=quot;quot;gt;EventEmitterlt;/codegt;.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;lt;code inline=quot;quot;gt;on()lt;/codegt;, lt;code inline=quot;quot;gt;once()lt;/codegt;, lt;code inline=quot;quot;gt;emit()lt;/codegt;.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Truyền dữ liệu qua sự kiện.lt;/pgt;lt;/ligt;lt;ligt;lt;pgt;Xây dựng hệ thống xử lý sự kiện theo mô hình Publisher–Subscriber (Pub/Sub) trong Node.js.lt;/pgt;lt;/ligt;lt;/ulgt;x1lt;br /gt;quay về lt;a href=quot;http://www.lophocvitinh.com/2026/08/nodejs-2026-tu-javascript-en-backend.htmlquot;gt;MỤC LỤClt;/agt;lt;br /gt;