dp-node
TypeScript icon, indicating that this package has built-in type declarations

0.3.11 • Public • Published

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

/dp-node/

    Package Sidebar

    Install

    npm i dp-node

    Weekly Downloads

    80

    Version

    0.3.11

    License

    MIT

    Unpacked Size

    127 kB

    Total Files

    48

    Last publish

    Collaborators

    • why2pac