Node.js
- 1 ответ
- 0 вопросов
0
Вклад в тег
server.js
var routes = require('./routes/');
var server = express();
routes(server);
routes/index.js
var fs = require("fs");
var path = require("path");
module.exports = function (server) {
fs.readdirSync(path.resolve(__dirname)).forEach(function (file) {
if (file.substr(-3, 3) === '.js' && file !== 'index.js') {
var full_path = path.resolve(__dirname) + '/' + file.replace('.js', '');
// console.log(full_path);
require(full_path)(server);
}
});
};
routes/test.js
var testController = require('../controllers/test');
module.exports = function(server) {
server.get('/test', testController.test);
};