0.0.10 • Published 7 years ago

shinjs v0.0.10

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

Shinjs

Shinjs is a MVC Node framework built on top of Express

Getting started

Installation

Requires Nodejs version > 4.5

$ npm install shinjs -g
$ shinjs new MyNewApp
$ cd MyNewApp
$ shinjs start

Now go to your browser and access the host and port

127.0.0.1:1337

Features!

  • Routing features that can overwrite controllers
  • Bind customized parameters to your controller and can be accessed in the res.locals
  • Render front-end dependencies using bower

Controllers

You can generate controller using the command:

$ shinjs generate Main -c

The generated controller is located in ./app/controllers/Main.js

"use strict"
module.exports = {
    //localhost:1337/main
    "index":['GET',function(req,res){

        // app/views/home.html
        res.render('home')

    },{title:'My Home Page',name:'home'}],

    //localhost:1337/main/hello
    "hello":['GET',function(req,res){

        res.send('world')

    },{title:'A hello world page',name:'hello_world'}]
}

Models

Shinjs uses the popular ORM Sequelize to provide models in our app ./app/models/Users.js

"use strict"
module.exports = function (sequelize, DataTypes) {
    var Users = sequelize.define("users", {
        username: DataTypes.STRING,
        email: DataTypes.STRING,
        password: DataTypes.STRING
    }, {
        classMethods: {
            associate: function (models) {

            },
            allUsers:function(callback){
                Users.findAll().then(function(users){
                    callback(null,users);
                })
            }
        }
    })

    return Users
}

Now to access the model

    "users":['GET',function(req,res){
        $.models.users.allUsers(function(users){
            res.render('home',{users:users});
        });
    },{title:'My Home Page',name:'home'}],

API

IO Use Socket io Instance

Models Database Models that is generated by Sequelize Access using:

$.models

Helpers Helpers are functions that can be shared between controllers and promote reusable and cleaner code. The api can be called and allows access to built-in and custom helpers.

var numbers = $.helpers.sampleHelper.add(1,2,3,4)
console.log(numbers) // 10

App Express app instance Locals: | variables | type | value | | ------------- |:-------------:| -----:| | params | object | name, title | | site_url | string | http://[hostname:port] | | form | objectfunction | generated form | | assets | object function | generated assets |

Config

These are app settings ranging from database to web configurations. You can override these config using .env file if provided. | Config | Description | values | :-------------: |:-------------:| :---------: | | database | Contains configuration for connecting to databse | host, port, name, username, password | assets | Assets overrides and for defining themes | [bower_url, assets_url, overrides (see wiredep), themes ] | web | App hostname and port configurations. Session key and storage | title, host, port, proxy, static_dir, timezone, session, session_secret, session_store | | views | Extension settings (.ejs, .html) | engine, ext

Development

Feel free to contribute by forking Shinjs. Current development status is alpha.

Roadmap

  • Built-in Task manager that can schedule and queue task (storage: database or memory)
  • Limit objects passed to the global variable $
  • API manager dashboard
  • API permissions

Todos

  • Write tests
  • Enhance API helpers and extensions
  • Add CORS to improve form restrictions
  • Allow custom plugin and more hooks

License

MIT