Skip to content

Node.js, Faster, cheaper, better web framework for Node.js

License

Notifications You must be signed in to change notification settings

why2pac/dp-node

Repository files navigation

dp-node

NPM Version NPM Downloads Dependency Status Linux Build Windows Build

Faster, cheaper, better web framework for Node.js, built on top of express.

Installation

$ npm install dp-node

Features

  • Rapid prototyping
  • async / await ready

Quick Start

Directory Structure

App
 ├─ controller
 │  ├─ foo
 │  │  ├─ bar
 │  │  │  └─ index.js
 │  │  └─ index.js
 │  ├─ bar
 │  └─ index.js
 ├─ model
 │  ├─ foo
 │  │  ├─ bar
 │  │  │  └─ index.js
 │  │  └─ index.js
 │  ├─ bar
 │  └─ index.js
 ├─ view
 │  ├─ foo
 │  │  ├─ foo.html
 │  │  └─ bar.html
 │  ├─ bar
 │  │  └─ baz.html
 │  └─ index.html
 └─ index.js

Controller

App/controller/foo/bar/index.js / http://localhost/foo/bar

module.exports = {
    async get() {
        /*
         *  `this` exports: {
         *     raw: {
         *        req: return express `req` object.
         *        res: return express `res` object.
         *     }
         *     model: return model accessor
         *     session: return model accessor
         *     params: (key, isURL)
         *     headers: (key)
         *     redirect: (url, statusCode)
         *     render: (view, params)
         *     finish: (body)
         *     finisher: {
         *        notfound: (body)
         *        invalid: (body)
         *        error: (body)
         *     }
         *     finishWithCode: (code, body)
         *  }
         */

        var arg1 = 10;
        var arg2 = 20;
        var res = this.model.foo.bar.add(arg1, arg2);  // == 30

        var params = {
            arg1: arg1,
            arg2: arg2,
            res: res
        };

        await this.render('foo/foo.html', params);
    }
};

Model

App/model/foo/bar/index.js / model.foo.bar

module.exports = {
    add(arg1, arg2) {
        /*
         *  `this` exports: {
         *     knex: (dsn)
         *     row: (query, params, dsn)
         *     rows: (query, params, dsn)
         *     execute: (query, params, dsn)
         *     tran: (blocks, dsn)
         *  }
         */

        return arg1 + arg2;
    }
};

Helper

App/helper/foo/bar/index.js / helper.foo.bar

module.exports = {
    add(arg1, arg2) {
        /*
         *  `this` exports: helpers
         */

        return arg1 + arg2;
    }
};

View

App/view/foo/foo.html / foo/foo.html

<p>{{arg1}} + {{arg2}} = <strong>{{res}}</strong></p>

Install

$ npm install dp-node

Dependencies

License

MIT

About

Node.js, Faster, cheaper, better web framework for Node.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages