A boilerplate of tools, examples, and tweaks to Bones to make getting started easier, Bones apps more flexible, and life less annoying for those that want to get started right away. The Bones project was created by the brilliant guys at Development Seed. It is a group of conventions for sharing code between a node.js server and a Backbone client for hopefully faster development.
One of the strengths of Backbone and Bones is flexibility. They do not try to enforce too much opinion on how you should build your application. This is wonderful for ubiquitous use of a library. But if you're like me and thirst for opinion or inspiration - if it annoys you to wade through stuff not directly related to your core product - then this library may be for you. Fork it, tear it apart, paint it green, whatever.
Beware: most of this code was just abstracted from a couple different projects, so it's a little rough around the edges :( I love issues so please make them.
Model API
.../api/<modelName>
. Assets
Backends
Rendering and Templating
Publishing and Commands
Utilities
<plugin>/<client|server>
and <plugin>/<client|server>/wrappers
Jekyll/Yaml Integration
url
from html files in a specified directory and creates a GET
end-point for that url and page.
Miscellaneous
bootstrapList
to Bones.plugin
- a list of functions executed in parallel that must be completed before starting the Bones server.
Libraries
Pushing bones-boiler to be additive, so just remove the dependencies and features of whatever you don't need.
require('bones-boiler')
after require('bones')
commands/Config.bones.js
with your specific MongoDB instance information
localhost:27017/bb
npm install
bones-boiler
directory, run:
rm -rf node_modules/bones/node_modules/backbone node_modules/bones/node_modules/jquery node_modules/bones/node_modules/mirror
to delete bones' backbone, jquery, and mirror dependency folders so bones-boiler can use its own versions.
node ./index.js
Requires mocha. See dev-dependencies in package.json. Run npm test
from bones-boiler root.
Some tips beyond the original documentation.
Models, views, routers, templates, servers, and commands folders each hold the core .bones.js files. These files are then wrapped with .prefix.js and .suffix.js before they are executed on either the client or server. Bones chooses what .prefix.js and *.suffix.js files are used to wrap the core files depending on where the code will be executed. If it's the server, node.js requires can be seen in the prefix file while client's will hold the beginning of a closure. This is how Bones provides conventions for declaration:
model.prefix.js
...
var model;
MyModel.bones.js
model = new Bones.Backbone.Model({});
Otherwise you are just building a Backbone application on the client and building an Express application on the server (with some Backbone code mixed in).
There seem to be three primary schools of thought concerning node.js and sharing Javascript code between the client and server:
The line of abstraction between client and server is absolute. Implementation of the client and server can freely change without worrying about the other.
The process on both the client and the server should reflect each other as reasonably as possible. Bones falls into this category in some ways.
The client and server should share functionality and design patterns, but remain loosely coupled enough to their independent components to change with a little work. The dark and dangerous grey area.
I personally subscribe to the third philosophy. I believe the client/shared/server architecture Bones uses is incredibly powerful. Identifying areas of shared functionality and structure, and then building independent client and server components from that foundation, creates a single core that can be quickly understood while maintaining flexibility.
Examples of shared functionality or structure:
model JSON schemas
utility functions or libs
rendering html
Examples of not shared:
client: Backbone view event handling and handlers
server: Access Control Lists for syncing data from a backend
By making use of shared code and using Backbone models as data models between the server and client, a server implementation does not have to tie itself to a single ORM for data modeling. However, certain components contain functionality irrelevant to the server. Backbone views used to only render a model leave a heavy memory footprint, for example.
This project tries to walk the fine line of shared functionality or structure. Hopefully this way, those coming from express can easily understand the server and quickly grasp some Backbone concepts, while those coming from Backbone can easily understand the client and quickly grasp some Express concepts.
Development Seed
Wiredcraft
@makara
Same as bones. BSD licensed.