Skip to content

Instantly share code, notes, and snippets.

@ganeshkbhat
Created February 2, 2024 06:25
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 ganeshkbhat/911b90a3b7d150d5bb59fc93eeabfa0e to your computer and use it in GitHub Desktop.
Save ganeshkbhat/911b90a3b7d150d5bb59fc93eeabfa0e to your computer and use it in GitHub Desktop.
after-middleware alternative
// after-middleware alternative - 2
const express = require('express');
const app = express();
const beforeMiddleware = function(req, res, next) {
console.log('Before middleware triggered');
next();
}
const responseHandler = function(req, res, next) {
console.log('Response Action implementation triggered with response instead of send');
res.status(200).send({"response":"fine-as-normal"});
}
const afterMiddleware = function(req, res, next) {
console.log('After middleware triggered');
}
app.get('/implement', beforeMiddleware, responseHandler, afterMiddleware);
app.listen(9001, '127.0.0.1', function() {
console.log('Server started at port ' + 'localhost' + ':' + 9001);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment