Created
April 1, 2013 17:56
-
-
Save jgable/5286522 to your computer and use it in GitHub Desktop.
Abstracting express routes
This file contains hidden or 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
var express = require("express"); | |
var routes = require("./lib/routes"); | |
// You're existing code to instantiate the app. | |
var app = express(); | |
// ... and configure it... | |
// Set your routes. | |
routes.init(app); | |
app.listen(3000, function(err) { | |
if(err) { | |
throw err; | |
} | |
console.log("Listening on port 3000"); | |
}) |
This file contains hidden or 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
var data = require("./data"); | |
module.exports = { | |
init: function(app) { | |
// Home page... | |
app.get('/', function(req, res) { | |
resp.render("index"); | |
}); | |
// Etc... | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment