Skip to content

Instantly share code, notes, and snippets.

@tsmx
Last active March 26, 2021 21:48
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 tsmx/e7f4a69571ea6c021a1e237b783640db to your computer and use it in GitHub Desktop.
Save tsmx/e7f4a69571ea6c021a1e237b783640db to your computer and use it in GitHub Desktop.
NodeJS Express - middleware function with custom parameter
var express = require("express");
var app = express();
const setMyInfo = (text) => {
return (req, res, next) => {
req.myInfo = text;
next();
};
};
app.get("/", setMyInfo("Test-123"), (req, res) => {
res.send("Hi there! myInfo = " + req.myInfo);
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment