I don't think it is a bad idea to factor out at all. An alternative
approach is to compose your routes and actually wire those up in
separate files. The pattern is passing in the app object to each file
(controller).

Sent from my Windows Phone
From: Glenn Scott
Sent: 5/31/2012 9:01 AM
To: nodejs
Subject: [nodejs] Laying out an API project using restify
I want to build out an API using restify.    I'd like to lay out the
project logically so it doesn't become a mess as it grows, but I also
don't want to get precious about it.  I'm looking for advice.

I was thinking that in the main module ("api.js" ) I would put all the
routes for every resource; and for the callbacks in each route I would
put the name of a handler that I export from a module that corresponds
to the resource, e.g., given a resource "dogs":

api.js:
--------

   var apiDogs = require( './lib/dogs.js');
   server.get('/dogs', apiDogs.dogHandler );

dogs.js
----------

   exports.dogHandler = function(req, res, next ) {
      // do lots of stuff here
      return next();
   });


Is this the right pattern?  Is there a better one?   Should I just put
everything into api.js and calm down?



-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to