so there can still be changes coming...
0.8.0 at the time of this slide's creation
Get to know your audience.
http://bccsurvey.meteor.comIt seems like there should be something better?
There is!
Node.js + MongoDB + Handlebars.js
Node is the Google Chrome V8 engine.
Allows us to write Javascript on the server.
The NoSQL database that handles state.
Document database, access on the server and the client.
{ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "name" : "mongo" }
{ "_id" : ObjectId("4c2209fef3924d31102bd84b"), "x" : 3 }
// find all documents in a collection
db.inventory.find( {} )
// find all inventory with type snacks
db.inventory.find( { type: "snacks" } )
// find all inventory with type snacks or food
db.inventory.find( { type: { $in: [ 'food', 'snacks' ] } } )
// Set the price and increment the stock count by 5
db.books.update(
{ item: "Divine Comedy" },
{
$set: { price: 18 },
$inc: { stock: 5 }
}
)
// Replace the entire document
db.books.update(
{ item: "The Banquet" },
{ item: "The Banquet", price: 19 , stock: 3 }
)
// Insert a new document
db.products.insert( { item: "card", qty: 15 } )
// resulting document
{ "_id" : ObjectId("5063114bd386d8fadbd6b004"), "item" : "card", "qty" : 15 }
JavaScript templating engine.
<a href="/posts/{{../permalink}}#{{id}}">{{title}}</a>
Handlebars.registerHelper('agree_button', function() {
return new Handlebars.SafeString(
"<button>I agree. I " + this.emotion + " " + this.name + "</button>"
);
});
// Example of calling helper function
<div class="button">
{{agree_button}}
</div>
That means no api calls to rest endpoints.
Instead of $.ajax({});
Collection.insert({});
Logs = new Meteor.Collection('logs');
// creates or connects to a mongo collection
db.logs
// on the server
Meteor.publish("rooms", function () {
return Rooms.find({}, {fields: {secretInfo: 0}});
});
// on the client
Meteor.subscribe("rooms");
Data drives the interface
Meteorite and Atmosphere
mrt add accounts-entry
mrt add jade
mrt update
New apps are insecure by default
// run this code everywhere, Server and Client
Logs = new Meteor.Collection('logs');
if (Meteor.isClient) {
// code only run on the client
// Template code
// Helper code
// Event code
}
// Only run on the server
if (Meteor.isServer) {
Meteor.publish('logs', function() {
return Logs.find();
});
// On server startup, if the database is empty, create some initial data.
Meteor.startup(function () {
if (Rooms.find().count() === 0) {
Rooms.insert({name: "Initial room"});
}
});
}
// free hosting for testing, not production ready
meteor deploy boisecodecamp.meteor.com
// install the modulus package from npm
npm install -g modulus
// authenticate
modulus login
// set the mongo env variable
modulus env set MONGO_URL "mongodb://username:pass@mongo.onmodulus.net:27017/database_name"
// deploy time
modulus deploy
// bundle up your code and install dependencies
meteor bundle ../myapp.tgz
cd ..
// untar
tar xzf myapp.tgz
// run the app in node
PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp node bundle/main.js
$ curl https://install.meteor.com/ | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4223 0 4223 0 0 2898 0 --:--:-- 0:00:01 --:--:-- 2898
Installing Meteor 0.7.1.2:
* 'meteor' build tool (version f3947a4651)
* Package updates: accounts-base accounts-facebook accounts-github
...
webapp weibo
Installed. Run 'meteor update' inside of a particular project
directory to update that project to Meteor 0.7.1.2.
$
$ meteor create chat
$ cd chat
$ meteor
[[[[[ ~/code/chat ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:3000/