声明:有点新的快递/节点,工作在照片托管/画廊应用程序作为实践。这是不正确的快递使用路线吗?
我的理解是路由器被用作从服务器到客户端/数据库的端点。
在这种情况下我有一个名为storeImages功能,其存储图像位置到DB而是被从节点JS应用程序内调用和不是直接从客户端请求。
我应该将storeImages作为路由器文件夹外的帮助函数吗?
我有点困惑,因为即使这不是从客户端post/get请求直接调用,我觉得这些images.js路由本质上与Image.js模型绑定在一起......并且数据库操作应该不存在于它之外。这样想我错了吗?
如果实际上最好将它保存在路由器文件夹中,那么将所述功能与路由器一起导出的正确方法是什么?低于目前的方法是行不通的,我也尝试:
module.exports = {路由器:路由器, storeImages:storeImages, }
但是,这也不能工作。
var express = require('express');
var router = express.Router();
var Image = require('../models/image');
router.get('/getImageLocations', function(req,res){
//Do Stuff
});
exports.storeImages = function(memoryId, location, comment){
var newImage = new Image({
...
});
Image.storeImageURL(newImage, function(err, user){
...
})
};
module.exports = router;
数据库函数可以放在模型文件中,而路径文件可以有其他功能,如检查特定端点的登录用户。 – 0xtvarun