Skip to content

Update to Express 4.0, express-handlebars, and organize code

Compare
Choose a tag to compare
@tilomitra tilomitra released this 13 Aug 15:10
· 7 commits to master since this release

In this version, I upgraded some of the project dependencies and organized the file and folder structure. The notable mentions for this release are:

Dependencies

  • Uses Express 4.x now (bumped up from Express 3.x)
  • Uses express-handlebars (previously known as express3-handlebars)

Project Structure

  • The config/ folder now stores config data for the app. This is also where commonly used paths are now stored.
  • There is now a routes/ folder, that exposes the routes.render(viewName) method. If you pass in a [viewName], it will render [viewName].handlebars. It also has a routes.redirect(url, statusCode) method.
  • The lib/ folder has some nice JavaScript and Handlebars helpers. I find the Handlebars helpers particularly useful. The following helpers are included:
    • {{addLocalJS}} - Supply a path to a local JS file and that file will get loaded.
    • {{addLocalCSS}} - Supply a path to a local CSS file and that file will get loaded.
    • {{addRemoteCSS}} - Supply a path to a remote CSS file and that file will get loaded.
    • {{setTitle}} - Sets the page title.

These helpers are useful for modularizing your JS/CSS on a per-page level, so you don't have monolithic stylesheets and JS files.

Front-end

  • Load jQuery 2.x and Bootstrap 3.x by default, since these are popular libraries that most people seem to use. If you want to remove them, just remove the references from views/layouts/main.handlebars.
  • Add an empty stylesheet to public/css/app.css so people can start modifying that.

Happy coding!