Skip to content

Instantly share code, notes, and snippets.

@shierro
Created June 28, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shierro/38d5697aed749661d89a0d12a2c04ce0 to your computer and use it in GitHub Desktop.
Save shierro/38d5697aed749661d89a0d12a2c04ce0 to your computer and use it in GitHub Desktop.
express.js
const UserController = {
get(req, res, next) {
try {
new Promise(resolve => setTimeout(() => resolve({ success: true }), 5000))
.then(res.json)
.catch(res.json);
} catch (e) {
next(e);
}
},
};
module.exports = UserController;
const UserController = require('./controllers/UserController');
module.exports = (app) => {
const router = express.Router();
/* APIs */
app.use('/api', router);
router.get('/user', UserController.get);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment