Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Last active August 29, 2015 14:04
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 adammcarth/1ba48ae0e61c54a8540b to your computer and use it in GitHub Desktop.
Save adammcarth/1ba48ae0e61c54a8540b to your computer and use it in GitHub Desktop.
// Require the express library
var express = require("express");
var router = express.Router();
router.get("/", function(request, response) {
response.render("index", { // "index" is the name of the view file to render (without extension)
title: "Welcome to my blog!" // Will be used for the HTML <title>
});
});
router.get("/posts", function(request, response) {
response.render("posts", {
title: "All Posts"
});
});
// In this example, I've used `:id`. That means the user can use anything
// in the place of `:id` and we can access its value. `/posts/6` for example.
router.get("/posts/:id", function(request, response) {
response.render("show", {
title: "Post Title Here, Eventually"
});
});
router.get("/add", function(request, response) {
response.render("new", {
title: "Add New Post"
});
});
router.post("/add", function(request, response) {
// add a new post here
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment