Created
January 22, 2020 15:58
-
-
Save prof3ssorSt3v3/c114ae6ae309458fa892e8f3ab297323 to your computer and use it in GitHub Desktop.
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
//Understanding Middleware | |
"use strict"; | |
const express = require("express"); | |
const app = express(); | |
const cors = require("cors"); | |
const { sup, how } = require("./middle"); | |
app.use(sup); | |
app.use(cors()); | |
app.get("/", how, sup, (req, res) => { | |
res.send({ data: "hi" }); | |
}); | |
app.listen(3000, err => { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
console.log("listening on port 3000"); | |
}); |
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
const sup = (req, res, next) => { | |
console.log(req.method); | |
console.log("sup"); | |
next(); | |
}; | |
const how = (req, res, next) => { | |
console.log("how you doin?"); | |
next(); | |
}; | |
module.exports = { sup, how }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment