在對的NodeJS控制器抽象是由你選擇使用框架定義。
例如,在Express中,您的控制器只是一個帶有兩個或三個參數的普通函數。
app.get('/users/find', function(req, res) {
//
// The 'req' object contains the request input information
//
// This will access the id in query param
// Ex: /users/find?id=12345
//
var userId = req.query.id;
// Then you'll find it in your database
Users.findOne({id: userId}).then(function(user) {
// The 'res' object holds the methods for serving responses
//
// Serve a JSON as response with user information
res.json(user);
})
});
很多流行的框架是明示或基於啓發,所以這將是在這樣SailsJS其他項目共同的結構。 關於快速結帳official website的更多信息。
感謝您的鏈接!很有幫助。 – mfcastro