From 94304ab328310d1ac274946b131c03d8e04a8072 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 22 Aug 2016 07:49:42 -0400 Subject: [PATCH] mvc for node --- node.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/node.md b/node.md index ebad9de..d9d0bfd 100644 --- a/node.md +++ b/node.md @@ -82,7 +82,11 @@ 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 +## MVC + +One of the main goals of express is to cleanly separate data from the view layer. To do this, it follows the Model View Controller pattern, which creates a middleman (Controller) which passes data (Models) off to the presentation/html (View) layer + +In addition, putting all your routes inside server.js can become difficult to maintain with a lot of variables. We can group similar urls together into separate "controller" files. ```javascript var runsController = require('./controllers/runs.js'); //require our own runsController @@ -99,7 +103,7 @@ controller.get('/', function(req, res){ //route for finding all routes by a the module.exports = controller; ``` -## MVC + ## Views ## Params/Query Strings ## REST