LoginSignup
0
0

More than 5 years have passed since last update.

Meteor をさわってみた

Last updated at Posted at 2014-12-22

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をみると、こんなんが表示される。

スクリーンショット 2014-12-22 19.39.07.png

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
  });
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0