Skip to content

Instantly share code, notes, and snippets.

@justinehell
Last active September 29, 2020 12:57
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 justinehell/0b5c8b5208d52c0243cafa0dc28579e4 to your computer and use it in GitHub Desktop.
Save justinehell/0b5c8b5208d52c0243cafa0dc28579e4 to your computer and use it in GitHub Desktop.
Routing sur Express
let express = require("express");
let app = express();
const port = 8000;
const userRouter = require("./users");
app.use("/users", userRouter);
app.listen(port, (err) => {
if (err) {
throw new Error("Something bad happened...");
}
console.log(`Server is listening on ${port}`);
});
const express = require("express");
const router = express.Router();
router.get("/", function (req, res) {
res.send("hello world");
});
router.put("/:name", function (req, res) {
res.send(`Hey my name is ${req.params.name}`);
});
router.delete("/:id", (req, res) => {
res.send(`Hey it's a DELETE ID ${req.params.id}`);
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment