Skip to content

TMJPEngineering/bes

Repository files navigation

bes.js

A friendly MVC Framework for Node.js

Build Status CircleCI

This framework uses ECMAScript 6 (ES6). See the ES6 standard for full specification of the ECMAScript 6 language.

Getting Started

To install the framework, run this command and you're good to go.

npm run setup

Features

  • Modular Structure
  • Passport
  • ES6 (ECMAScript 6)
  • Ready-made commands
    • npm test (For Testing)
    • npm start (Run framework using Babel)
    • npm run reload (Watch all the files)
    • npm run setup (Install framework)
    • npm run dev (Run webpack in development mode)
    • npm run prod (Run webpack in production mode)
    • npm run watch (Watch all files)
    • npm run db:seed (Import fake data)
  • Bootstrap 4 (Beta)
  • MVC Architecture
  • TDD (Using karma and jasmine)
  • CI (Using CircleCI or Travis)
  • Helpers (e.g. env, logger, etc.)
  • Database Seeder
  • Socket.io

Usage

Route Methods

GET Method

Route.get('<uri>', '<controller>@<method>|<closure>', [<middlewares>]);

POST Method

Route.post('<uri>', '<controller>@<method>|<closure>', [<middlewares>]);

UPDATE Method

Route.update('<uri>', '<controller>@<method>|<closure>', [<middlewares>]);

DELETE Method

Route.delete('<uri>', '<controller>@<method>|<closure>', [<middlewares>]);

RESOURCE Method

Route.resource('<uri>', '<controller>', [<middlewares>], {only|except});

VIEW Method

It loads a html file.

Route.view('<uri>', '<file>', [<middlewares>]);

ALL Method

This method is used for loading middleware functions at a path for all request methods.

Route.all('<uri>', '<closure>');

In resource method, it provides get, post, update, and delete method. These are the following methods in controller that uses resource method:

  • index for GET Method
  • create for GET Method
  • store for POST Method
  • show for GET Method
  • edit for GET Method
  • update for UPDATE Method
  • destroy for DELETE Method

You can also limit by using only or except. See example below:

Example #1

export default () => {
    namespace('User'); // or
    namespace(modules.user); // Located in modules/User
    ...
    Route.resource('/user', 'UserController', ['client'], {
        only: ['index', 'show']
    });
    ...
};

Example #2

export default () => {
    namespace('Blog'); // or
    namespace(modules.blog); // Located in modules/Blog
    ...
    Route.resource('/api/blog', 'BlogController', ['oauth'], {
        except: ['create', 'edit']
    });
    ...
};

Example #3

export default () => {
    namespace('Home'); // or
    namespace(modules.home); // Located in modules/Home
    ...
    Route.view('/home', 'pages.home');
    // It says that route will load the html file in /resources/views/pages/home.html
    ...
};

Note: Every routes file must have a namespace inside the function. Always put it in the first line.

Route Groups

Route.group({ prefix: 'lorem', middleware: ['foo', 'bar'] }, () => {
   ...
   // Insert route methods here
   ...
   Route.endGroup();
});

TODO

  • Nested Route Groups
  • bes command line interface (cli)

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details