我有這個基本結構./api/controllers/authenticate.js
和./api/models/authenticate.js
我想讓我的控制器訪問模型文件夾中的authenticate.js
,如此處所示。模型文件夾中找不到模塊
控制器/ authenticate.js
var app = require("express");
var router = app.Router();
var model = require("./api/models/authenticate.js");
router.get('/login',function(req,res){
res.send(model.authenticate());
});
module.exports = router;
型號/ authenticate.js
var authenticate = function() {
return "You should see this module";
}
module.exports = authenticate;
但是我得到一個無法找到的模型文件authenticate.js模塊。我錯過了什麼?
var model = require(「./../ models/authenticate.js」); –
和res.send(model()); –
此外,我總是使用我的絕對路徑的路徑模塊。 'var absPath = path.join(__ dirname,'../ models/authenticate.js');'。最後,只要解決了問題就沒有關係,但是當你缺少某些東西時,它可以更容易地調試路徑。 – Quy