Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created January 22, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/c114ae6ae309458fa892e8f3ab297323 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/c114ae6ae309458fa892e8f3ab297323 to your computer and use it in GitHub Desktop.
//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");
});
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