您好我是新手来表达js我想在路线中放置多个功能,请解释我如何在路线中添加多个功能,我在company.js中有2个功能但是我不知道如何导出它并将其添加到index.js
index.js
adb shell settings put global stay_on_while_plugged_in 1
adb shell input keyevent 26
company.js
var router = require('express').Router();
var path = require('path');
// Rest API
require(path.join(__dirname, './', 'company'))(router);
// Homepage/Client
router.get('/', function(req, res, next) {
res.sendFile(path.join(__dirname, '../', 'client', 'index.html'));
});
module.exports = function(app, passport) {
// set authentication routes
require('./authentication.js')(app, passport);
// set other routes
app.use('/', router);
};
答案 0 :(得分:3)
您可以按如下方式导出这两个功能
module.exports = {
getCompanyProfile: getCompanyProfile,
saveCompanyProfile: saveCompanyProfile
}
并导入 index.js ,如下所示
const company = require('./company.js');
company.getCompanyProfile(router);
company.saveCompanyProfile(router);