Skip to content

Bearcat的helloworld

fantasyni edited this page Jun 9, 2014 · 3 revisions

让我们开始Bearcat开发之旅,"HelloWorld"实例

在项目中使用bearcat

  • 添加bearcat的npm项目依赖
npm install bearcat --save
  • 编写简单的 POJOs 创建app文件夹, 在该文件夹内编写helloBearcat.js
    app/helloBearcat.js
var HelloBearcat = function() {
	// $ based parameters annotation defines POJO id
	this.$id = "helloBearcat";
}

HelloBearcat.prototype.hello = function() {
	console.log('hello bearcat');
}

module.exports = HelloBearcat;
  • 编写简单的元数据定义 context.json
{
	"name": "helloBearcat",
	"scan": "app"
}
  • 编写主函数来把helloBearcat应用程序跑起来 app.js
var bearcat = require('bearcat');
var contextPath = require.resolve('./context.json');

bearcat.createApp([contextPath]);
bearcat.start(function(){
   var helloBearcat = bearcat.getBean('helloBearcat');
   helloBearcat.hello();
});
  • 跑起来
node app.js

项目的完整代码在 helloBearcat