In a real-world web application, how does Express improve developer productivity compared to vanilla Node.js when handling HTTP requests?
4 phương ánCó giải thích
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: "Express provides a routing system and middleware pipeline to streamline request processing". Với module http thuần, lập trình viên phải tự đọc req.url và req.method, tự viết chuỗi if để định tuyến, tự phân tích query và body; Express gói những việc đó thành hệ định tuyến (app.get, app.post, express.Router, tham số đường dẫn như /users/:id) và chuỗi middleware chạy lần lượt qua next(), nhờ đó các bước như phân tích JSON, xác thực, ghi log được tách thành hàm tái sử dụng. "Express automatically compiles JavaScript into machine code" sai vì biên dịch JIT là việc của engine V8 trong Node.js, Express không can thiệp. "Express eliminates the need for external modules" sai vì Express vẫn được dựng trên module http của Node.js, chỉ che bớt chi tiết chứ không loại bỏ nó. "Express includes a built-in database driver for MongoDB" sai vì Express không kèm driver cơ sở dữ liệu nào; muốn dùng MongoDB phải cài thêm gói mongodb hoặc Mongoose.
Cùng chương 3
______ is a fast, unopinionated and minimalist web framework for Node.jsCó lời giảiCâu hỏiHow do you add middleware to an Express application?Có lời giảiCâu hỏiConsider the following code snippet using Express.js. Identify which routes handle GET and POST requests. app.get('/users', ...); app.post('/users', ...); app.listen(3000, ...) (Choose 2 answers)Có lời giảiCâu hỏiCả 38 câu của chủ đề38 câu