do-faramework is SIMPLE Node.js framework.
- Very simple in structure, easy to custom.
- There are very few CALLBACK, source code is easy to see.
- Easy to see the working directory of programmers and designers.
Before installing, download and install Node.js and npm.
npm -g install do-framework
Project directory can be created with the following command.
do-framework [project name]
①. 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!
①. 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!
①. 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
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.