An experiment to create a framework that is quick to setup, and easy to test.
npm installnode app.js or use a process manager, e.g. pm2 start app.jsAssets are kept in the assets folder. Running grunt will automatically watch the assets folder and keep it in sync it for development. Everytime an asset changes it's copied/processed into to the .tmp/public folder. For example, SCSS files are compiled and unminified when they are changed.
For production, run grunt build this copies, minifies, et cetera, the assets into the www folder. This is the folder that should be used as the static asset folder on a production server.
Routes are defined in config/routes.js:
// Format
'VERB /uri' : '*Controller.action',
// Examples
'GET /' : 'IndexController.index',
'GET /users' : 'UserController.users',
'POST /user' : 'UserController.post',
Controllers are automatically loaded from the api/controllers/ folder. Only
files ending in Controller.js are read, e.g. HomeController.js.
module.exports = function(sol){
return {
// This action is passed directly to express. req and res allow access
// to Express.js request and response objects
index: function(req, res) {
sol.user.find().exec(function(err, model){
if(err) {
res.status(500).send('Unable to create model');
}
return res.json(model);
});
},
users: function(req, res) {
return res.render('projects');
}
};
}
Sol.js use Waterline as an ORM.
Model definitions are automaticall loaded from the api/models/ folder. Only
files ending in Model.js are read, e.g. UserModel.js.
module.exports = {
identity: 'User', // This name is used in Controllers to access it
connection: 'localDisk', // Adapter defined in config/connections
attributes: {
firstName: 'string',
lastName: 'string'
}
};
Views are located in the views folder and use ejs by default; To render a view,
use the res.render(view, data) function in a controller action.
All JS follows Google Coding Standards. This can be changed in .jscsrc. Every time
grunt detects a change in code, it automatically checks for linting issues,
coding standards, and unit tests. Prior to every commit, all three must pass.
Grunt configuration files are split into two directorys and automatically loaded.
Each task gets its own file in the tasks/config directory. Additional custum
tasks are registered in the tasks/regsiter folder.
Be default cookies are used. To enable Redis, uncomment out the adapter line in
config/sessions.js
// adapter: 'redis', // Uncomment this to enable
redis: {
host: 'localhost',
port: 6379,
ttl: 24 * 60 * 60,
db: 0,
pass: 'secret',
prefix: 'sess:'
}
Bower components are automatically installed in the assets/components folder
and intergrated into the asset pipeline