Meteor 1.0.2
$curl install.meteor.com | /bin/sh
インストール終わるとこんなんが表示される。
Meteor 1.0.2 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
To get started fast:
$ meteor create ~/my_cool_app
$ cd ~/my_cool_app
$ meteor
Or see the docs at:
docs.meteor.com
新規プロジェクトはmeteor createで作成する。
$mkdir ~/meteor-sample
$cd meteor-sample
$meteor create ./my-first-meteor
プロジェクトの作成が終わるとシンプルなメッセージが表示される。
my-first-meteor: created.
To run your new app:
cd ./my-first-meteor
meteor
ディレクトリを移動し、appサーバーを起動する。
$cd ./my-first-meteor
$meteor
[[[[[ ~/my-first-meteor ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:3000/
localhost:3000をみると、こんなんが表示される。
websocketっぽい感じで、Click Meとかかれたボタンを押すとスイスイとカウンターがアップする。とりあえずここはCtrl+Cでサーバーを停止。
さて、ファイル階層
$tree
.
├── my-first-meteor.css
├── my-first-meteor.html
└── my-first-meteor.js
0 directories, 3 files
へ、これだけなんだ。
CSSはカラやったけど、他の二つはこんな感じ。
my-first-meteor.html
<head>
<title>my-first-meteor</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> hello}}
</body>
<template name="hello">
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>
my-first-meteor.js
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault("counter", 0);
Template.hello.helpers({
counter: function () {
return Session.get("counter");
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set("counter", Session.get("counter") + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
