Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
building_on_node_and_exposing_functionality [2012/12/08 03:41]
admin
building_on_node_and_exposing_functionality [2012/12/08 03:52]
admin [Exposing Events]
Line 4: Line 4:
  
 === Exposing Events === === Exposing Events ===
 +
 +By default node js files only have scope within the same file. We can use the nodejs method "​export"​ to export what ever we need to expose functions or variables ​
 +
 +<code javascript | myFile.js>​
 +var x = 5;
 +var addX = function(value) {
 +  return value + x;
 +};
 +module.exports.x = x;
 +module.exports.addX = addX;
 +</​code>​
 +
 +
 +This is then included into other scripts with 
 +
 +<code javascript>​
 +var myExposedStuff ​ = require('​./​myFile'​);​
 +</​code>​
  
 
building_on_node_and_exposing_functionality.txt · Last modified: 2012/12/08 03:52 by admin
 
RSS - 200 © CrosswireDigitialMedia Ltd