Which of the following statements correctly describe the process of creating and starting an HTTP server in Node.js?
4 phương ánCó giải thíchTrung bình
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng gồm hai ý: "The http.createServer method is used to create a server instance." và "The server.listen method is used to start the server and listen for incoming requests.". Quy trình chuẩn là nạp module có sẵn bằng require('http'), gọi http.createServer với một hàm nhận req và res để có đối tượng server, rồi gọi server.listen với số cổng để máy chủ bắt đầu lắng nghe; mỗi request tới sẽ kích hoạt hàm xử lý đã truyền. "The require('http') statement is used to install the http module." sai vì require chỉ nạp module vào mã đang chạy chứ không cài đặt gì, và http là core module có sẵn trong Node.js nên không cần cài. "The npm i http command is used to require the http module in your code." trộn lẫn hai việc: npm i là lệnh cài gói từ kho npm vào node_modules, chạy ở dòng lệnh, còn việc nạp module trong mã là của require; hơn nữa module http lõi không cần cài bằng npm.
Cùng chương 2
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây