rode.js
Packet-Oriented Framework for ES6 and Express.
Table of Contents:
- ECMAScript 6
- Getting started
- Packages
- Models
- Controllers
- Routes
- Middleware on Routes
- Restful APIs
- Templates engines
- Tests
ECMAScript 6
rode.js framework is a stable way to use ES6 today. ES6 support is provided by traceur, es6-shim and es6-module-loader.
rode.js is based on Express, but we not rewrite it, you can still using all the features of Express.
Getting started
Install rode.js globally and generate a new project:
# npm install -g rode
$ rode new --view ejs --css less --sessions myProject
Install project dependencies:
$ npm install
Start the server:
$ node app
Usage of rode new
:
Usage: rode new [options] [dir]
Options:
-h, --help output usage information
-V, --version output the version number
-v, --view add view engine support (jade|ejs|hogan|soy) (defaults to jade)
-c, --css add stylesheet support (less|stylus|css) (defaults to plain css)
Packages
A package (or bundle) is a component of your application with its own MVC.
You can simply create a new package with the command:
$ rode generate PackageName
Usage: rode generate package <package>
Options:
-h, --help output usage information
-r, --rest config rest api for this package
-f, --force force on existing package
Models
In a model you should add all your business logic:
; /** * Sample method, converts a string to upper case */ { return str; }
You can generate a Model myModel
for a package User
with the command:
$ rode generate User:model myModel
Controllers
Controllers and Routes works together to facilitate the routing of the application.
A controller looks like:
/** * sayHello Action */ { res; }
You can generate a Controller myController
for a package User
with the command:
$ rode generate User:controller myController
Routes
A route for the above controller looks like:
;var router = ; /** * [GET] / * Calls HelloController.sayHello */router; ;
Middleware on Routes
Here's an example of how to define a middleware on routes:
{ return { // Check permissions ; } { // Show Private Data } ; }
Restful APIs
Make a Restful API can not be more easy.
Create your REST package with the command:
$ rode generate package PackageName --rest
Or add router.restApi = '/api/products';
on the routes.js
of any package.
Now you should create methods on your RestController.js
following simple naming conventions.
Here are some examples:
// [GET] /api/products { ... } // [POST] /api/products { ... } // [GET] /api/products/sponsored { ... } // [PUT] /api/products/sponsored { ... } // [POST] /api/products/sponsored/today { ... } // [GET] /api/products/:id { ... } // [POST] /api/products/:id { ... } // [DELETE] /api/products/:id { ... } // [GET] /api/products/:id/comments { ... } // [PUT] /api/products/:id/comments/:id2 { ... }
You can create as many combinations as you like.
Remember that each package can have its own RestController.js
Templates engines
rode.js supports all this templates engines:
- Jade (default template)
- Ejs (using ejs-locals)
- Hogan.js
- Google Closure Templates
- Since you still can use express, you can use any template that express support
Tests
You can run the test with the command:
$ grunt test