Meteor is an open source real time JavaScript framework for building web apps. Telescope is a fabulous implementation of the meteor framework created by Sacha Greif. You can use Telescope to build your own social news website similar to Hacker News or Reddit. Sacha has recently released a new version of Telescope. The new version includes a great feature called "Post Modules" that allows you to add or remove features from Telescope in a modular fashion. I am using an older version of Telescope on stackde.com which did not come with a default implementation for embedding images with your posts using Embedly. I had to some minor hacks to get Embedly working with Telescope. You can find the changes in the gist here. But in the new version of Telescope, you can use the Post Modules feature to enable the Embedly feature in a much cleaner way. Sacha has a great post that demonstrates doing just that. Check out the post here.

For an excellent introduction to the meteor framework watch this video by Sacha.




Posted
AuthorMurali Narasimhan
CategoriesTechnology

var myModule=require("./myModule");

Using require like this assigns the value of module.exports from the module myModule. Our myModule looks like this:

//myModule.js
var func1=function(a){
  return a*a;
}
exports.func1=func1;

Wait a minute! We are using exports to export the functions from the module, not module.exports. Are they the same? Turns out that exports is a reference to module.exports that is shorter to type. exports is not global but local to each module.

It is like declaring the following at the top of each of your modules:

var exports=module.exports;

All of this works fine if we are assigning all the exports from your module as properties (like in the myModule definition above). What happens if we did something like this:

//myModule.js
var func1=function(a){
return a*a;
}
exports=func1;

Nothing gets exported - module.exports will be empty. Why? Remember exports is just a variable and when we assign something else to it, it is no longer referring to module.exports.

If you need to export a function or a complete object from your module, assign it to module.exports instead of exports.

//myModule.js
var func1=function(a){
return a*a;
}
module.exports=func1;
Posted
AuthorMurali Narasimhan
CategoriesTechnology