Last active
August 29, 2015 14:04
-
-
Save adammcarth/1ba48ae0e61c54a8540b 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
// 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