https://github.com/MiguelValentine/GDK
欢迎 issues
GDK is a global based framework for node.
$ npm install gdk
No.GDK dose not support quick start.And I will not provide a generator.
I don't think less is best.I can guide you to make your our service different with anyone.
At First make sure that your env is in your project and you npm installed gdk.
You can download Learning Project.
1.Create bin File to guide - bin/start.js
require('gdk')
var baseDir = __dirname;
gdk.load(gdk.c.path.join(baseDir,'../config'));
gdk.boot();
gdk.load(gdk.c.path.join(baseDir,'../http'));
gdk.cluster(function(){
gdk.http.boot();
});
2.Create config File - config/index.js
var baseFile = __filename;
gdk.updatePath.config = baseFile;
gdk.config.Mcores = true;
gdk.config.errLog = gdk.c.path.join(__dirname,'../err.log');
gdk.config.port = 3000;
3.Create http base - http/index.js
gdk.updatePath.http = __filename;
gdk.http = {};
gdk.load(gdk.c.path.join(__dirname,'./router'));
gdk.load(gdk.c.path.join(__dirname,'./flow'));
gdk.load(gdk.c.path.join(__dirname,'./instance'));
4.Create flow file - http/flow/index.js
gdk.http.flow = function(req,res){
if(gdk.http.router[gdk.c.url.parse(req.url).path]){
gdk.http.router[gdk.c.url.parse(req.url).path](req,res);
}else{
res.end();
}
}
5.Create router file - http/router/index.js
gdk.http.router = {};
gdk.http.router['/'] = function(req,res){
res.end('Hello World!');
}
6.Create instance file - http/instance/index.js
gdk.http.server = function(req,res){
gdk.http.flow(req,res);
};
gdk.http.boot = function(){
var server = gdk.c.http.createServer(gdk.http.server);
server.on('error',function(err){
gdk.errCatch('server err',err);
});
server.listen(gdk.config.port);
};
7.Run
node bin/start.js
Example:
bash
bash---console.log(gdk.config)
Example:
bash
update---config
Example2:
bash
upfile---/node/http/index.js
Example:
gdk.runTime.print = function(info){
console.log(info)
}
print---here is a test
In gdk Cluster mode.gdk.cluster(cb).cb will always run on workers.
Workers can use process.send to call a runtime function in all workers or master.
Example:
```
gdk.runTime.print = function(a,b){
console.log(a+b)
}
process.send({bash:'print',arg:{'hello',' world'}});
```
Example:
```
gdk.runTime.MainCore = function(a,b){
console.log(a+b)
}
process.send({bash:'MainCore',arg:{'hello',' world'},Master:true});
```
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.