ohm - Node.js Starter Application
ohm is an opinionated full-stack Node.js environment to jumpstart a web project. Based on Express, ohm uses Grunt for automation, Compass (SASS) for CSS pre-processing and npm & bower for dependencies. It also integrates the Ghost blogging platform as a CMS. ohm is designed to be run proxied by Nginx. For more see dock. I've included some basic mixins and figures that can be helpful in making web layouts quickly, I also am going to gradually integrate Bootstrap features. ohm comes preconfigured with production/development environments (production minifies all files including the html markup) as well as example server config files (using Nginx to serve static files, and proxying ohm and ghost).
Features
- HTML5 ready. Use the new elements with confidence.
- CSS resets (normalize.css) and common bug fixes.
- Compression and spriting of images
- Designed with progressive enhancement in mind.
- An optimized Google Analytics snippet.
- Make powerful use of
grunt watch
- Adhere to Steve Sauders Rules for High Performance Websites:
Installing
If you are confident that your environment is properly configured skip this, but installing the app is very easy using dock
git clone https://github.com/ohmlabs/ohm.git your-repo
cd your-repo
npm install -g ohm
ohm install
ohm dev
ohm prod
Dependencies:
Running
In development, we use forever and grunt to start the server as a daemon. The cli takes care of this:
ohm start
ohm stop
ohm list
grunt watch
grunt watch
To best streamline the development process this project uses grunt.js (a JavaScript Task Runner). There is so much that you can automate with grunt, but the included gruntfile is includes a powerful watch task with the following features:
- Automatic browser reloading (LiveReload) chrome extension
- Automatic Sass compilation and css injection (browser-snyc)
- Automatic concatination, minification, validation (lint, plato) and CoffeeScript compilation
- Automatically restart ohm on server file changes (Forever)
Architecture
ohm attempts to have the simplest possible structure. Code is grouped into three main classes: server, client, and static. The server directory contains the files that reside on the server (views to be rendered, logic for the app). I actually lied when I said there were three classes because the Static and Client directories are actually the same thing. The client directory contains pre-compiled code that the user will need on the client-side for the app (Sass files and Javascript code). The static directory files are all generated automatically in the grunt compile process (client/sass files are compiled to static/css, client/js files are concated and/or minified into one file which is compiled into static/js). You should NEVER have to edit static files, they should be generated automatically (except in the case of adding images or other filetypes that are not a part of the compile process e.g. *.php or *.txt)
If you are a designer most of your time will be spent in the client directory. If you are a back-end developer you'd work predominately in the server folder.
├── bin
│ └── ohm
├── client
│ ├── js
│ ├── images
│ └── sass
├── logs
│ ├── ohm-error.log
│ └── ohm.log
├── server
│ ├── apis
│ ├── config
│ ├── models
│ ├── ghost
│ | ├── content
│ | └── config.js
│ ├── controllers
│ ├── routes
│ └── views
│ | └── includes
├── static
│ ├── components
│ ├── css
│ ├── img
│ ├── js
│ ├── jsdoc
│ └── plato
├── bower.json
├── package.json
├── gruntfile.coffee
├── .bowerrc
├── .gitignore
├── .jshintrc
├── ohm.coffee
└── ohm.js
Versioning
The best thing about this ohm is that when used in conjunction with our dock repo can be used to fully deploy a node.js web app. First you must generate production assets, and then version your app. To only generate production assets, first checkout a production branch. You can compile and test the app with new static assets. Once you are satisfied and ready to release execute the ohm version
command:
- compiles production assets
- bumps the version tag for git
- compresses images
grunt prod; node ohm.js -p
git add .
git ci -m 'pushing to production'
ohm version
git push production prod
git push origin prod
Extending
ohm is built to be easily extended to include many additional features.
Client Dependencies
There are a few client-side add-ons included via Bower. There are advantages to each of these libraries and I would certainly not recommend using them all together as it can really add in terms of HTTP requests and page download size (remember Souders rules!). Modernizr is useful for any project. Many users love using underscore and/or jQuery. Personally I prefer to use d3 instead of jQuery. Although it's larger in terms of download size it can do a lot of the same things jQuery can do and a whole lot more. Skrollr is very useful if you are working on a single page app or want to add parallax effects to your site. Finally, socket.io is a great library for building a real time web app.
Documentation & Validation
This command will generate jsdoc documentation and perform jslint on both client and server files. An added bonus here is Plato, which will run jshint and get data on complexity analysis on your javascript files.
ohm docs
Debugging
The dock repo includes node-inspector in the global node modules that were installed, so learn more about how to use it. The gruntfile by default passes the necessary flag to run the debugger, but you must start node inspector:
node-inspector &
Profiling
You can profile your servers performance using strongOps. All you need to do is sign up for an account.
$ cd your-app-dir
$ slc strongops --register
Roadmap
- Amazon Web Services integration
- Parse backend integration
- Socket.io integration
- Require.js support
- Support multiple templating platforms (.hbs, .jade, angular etc.)
- Yeoman Generator
- Ghost Theme
License
ohm is licensed under the MIT license