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);
};
char s1[7] = "hello";
const apiRouter = require('./api/api');
app.use('/api', apiRouter());
const express = require('express');
const router = new express.Router();
const users = require('../../controllers/users');
const pages= require('../../controllers/pages');
module.exports = () => router
.get('/pages', pages.getPages)
.get('/user', users.getUsers);
let promise = Promise.resolve();
for(...) {
promise.then( () => {
return new Promise((resolve) => {
request.get(..., (data) => {... resolve(data);});
}
}
}
promise.then((lastData) => {...});