$ curl https://install.meteor.com | /bin/sh
$ meteor create myapp
$ cd myapp
$ meteor
=> Meteor server running on: http://localhost:3000/
if (Meteor.isClient) {
// code to run on client
...
}
if (Meteor.isServer) {
// code to run on server
...
}
/client/...
/server/...
/lib/...
/public/...
main.*
Posts = new Meteor.Collection("posts");
Posts.find();
Posts.findOne();
Posts.insert();
Posts.update();
Posts.remove();
...
// server: publish the messages collection
Meteor.publish("messages", function () {
return Messages.find();
});
// client: subscribe to the published messages
Meteor.subscribe("messages");
Meteor.methods({
foo: function (arg1, arg2) {
// .. do stuff ..
if (you want to throw an error)
throw new Meteor.Error(404, "Can't find my pants");
return "some return value";
},
bar: function () {
// .. do other stuff ..
return "baz";
}
});
// async call
Meteor.call('foo', 1, 2, function (error, result) { ... } );
// sync call
var result = Meteor.call('foo', 1, 2);
Messages.allow({
insert: function (userId, msg) {
// only logged-in users can insert a new message that they own
return (userId && msg.owner == userId);
},
fetch: ['owner']
});
Messages.deny({
remove: function (userId, msg) {
//can't remove locked messages
return msg.locked;
},
fetch: ['locked']
});
<head>
<title>myapp</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>
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);
}
});
}
$ meteor add accounts-ui
$ meteor add accounts-*
* = password, facebook, twitter, google, github, ...
OAuth2
{{> loginButtons}}
$ meteor deploy myapp.meteor.com
$meteor deploy www.myapp.com
$ meteor bundle myapp.tgz