do-framework

0.0.29 • Public • Published

Abstract

do-faramework is SIMPLE Node.js framework.

Features

  1. Very simple in structure, easy to custom.
  2. There are very few CALLBACK, source code is easy to see.
  3. Easy to see the working directory of programmers and designers.

Installation

Before installing, download and install Node.js and npm.

npm -g install do-framework

Create Project

Project directory can be created with the following command.

do-framework [project name]

Example(http server)

①. create file "/back/http/controller.js" and input the following code.

【controller.js】

var Do = module.parent.exports.Do;

exports['action'] = function* (req, res) {
    return Do.output.view('controller/action', { title: 'TEST TITLE' });
}

②. create file "/front/view/controller/action.ejs" and input the following code.

【action.ejs】

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><%= title %></title>
</head>
<body>
test
</body>
</html>

③. start http server in root of project directory

npm run start

④. access http or https ://host:port/controller/action

you can see sample page!

Example(socket.io)

①. create file "/back/http/controllerio.js" and input the following code.

【controllerio.js】

var Do = module.parent.exports.Do;

exports['actionio'] = function* (req, res) {
    return Do.output.view('controller/viewIo', { title: 'TEST TITLE2' });
}

②. create file "/front/view/controller/action.ejs" and input the following code.

【viewio.ejs】

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><%= title %></title>
</head>
<body>
    <script src="/js/jquery.min.js"></script>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect('/test');
        socket.emit('send', "test");
        socket.on('send', function (data) {
            alert(data);
        });
    </script>
</body>
</html>

③. create file "/back/io/test.js" and input the following code.

var Do = module.parent.exports.Do;
exports['send'] = function* (socket, data) {
    socket.emit('send', 'sended!');
}

④. start http server in root of project directory

npm run start

⑤. access http or https ://host:port/controllerio/actionio

you can see "sended!" alert!

Example(batch)

①. create file "/back/batch/test.js" and input the following code.

【test.js】

var Do = module.parent.exports.Do;

exports['go'] = function* (args) {
    console.log("batch done!")
    return "OK";
}

②. start batch in root of project directory

npm run batch test/go

you can see "batch done!" text in console

Boot option

see package.json

:
  "scripts": {
    "start": "NODE_ENV=ENV1 NODE_BATCH=0 node app.js",
    "batch": "NODE_ENV=ENV1 NODE_BATCH=1 node app.js"
  },
:

NODE_ENV

When boot node, load config file in config/【NODE_ENV】 directory
e.g.
LOADED config/ENV1/Do.js
LOADED config/ENV1/http.js
LOADED config/ENV1/mongo.js
LOADED config/ENV1/mysql.js
LOADED config/ENV1/redis.js

NODE_BATCH

execute batch program or not.

Readme

Keywords

none

Package Sidebar

Install

npm i do-framework

Weekly Downloads

1

Version

0.0.29

License

MIT

Unpacked Size

291 kB

Total Files

99

Last publish

Collaborators

  • ujihara.test