Organization of games in an express.js app

I have a server that runs several multi-player web games. It is built in Node.js+Express.js, with a standard folder structure (e.g. Jade files under "views", Javascript client files under "public/javascripts", etc.).

Whenever I add a new game, I have to:

  • Add its Jade file to "views/"
  • Add its Javascript file to "public/javascripts/"
  • Add its relevant event handlers to a Node.js file in another folder
  • Add code to the main file (server.js) that refers to all these new files.

This seems like a sub-optimal organization, because the files related to each game are scattered in many folders.

Can you suggest a better structure, where the code of each game will be encapsulated in a single place?

TJ Holowaychuk, creator of express, just released a video on vimeo showing you how to build modular web applications using express. This video is available here and answers your questions directly: http://vimeo.com/56166857.

The idea is to have one lib/ folder containing self contained express apps in subdirectories with public, views directories in each subdirectory. You then export each app object and link all of them in one file.