Last active
March 26, 2021 21:48
-
-
Save tsmx/e7f4a69571ea6c021a1e237b783640db to your computer and use it in GitHub Desktop.
NodeJS Express - middleware function with custom parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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