From be7c63126b0490d302f74fb21d3c7af71141a9c0 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Sun, 21 Aug 2016 21:56:27 -0400 Subject: [PATCH] finishing routing --- node.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/node.md b/node.md index a5a1db9..ebad9de 100644 --- a/node.md +++ b/node.md @@ -82,6 +82,23 @@ app.get('/', function(req, res){ // route for / This sets up an event listener for any GET request that comes into the server with the path of `/`. Give it a callback function which takes a request variable and a respond variable. Each of these have different methods/properties which we'll learn about +This can get difficult to maintain with a lot of variables, so we can group urls together + +```javascript +var runsController = require('./controllers/runs.js'); //require our own runsController +app.use('/runs/', runsController); //use it for anything starting with /runs +``` + +Now, in a separate file, we can use: + +```javascript +var controller = require('express').Router(); //require express and create a router (controller) +controller.get('/', function(req, res){ //route for finding all routes by a the session user + res.send('runs index'); +}); +module.exports = controller; +``` + ## MVC ## Views ## Params/Query Strings