Hello World: lnugExample1.js
A simple hello world example used as the introductory example during our LNUG presentation. For more details see the presentation slides.
var _ = require('underscore') ;
var colors = require('colors') ;
function lnugExample (fire, name) {
return {
startState: "HelloWorld",
states: {
"HelloWorld": {
entry: function () {
fire.process.stdout.write("Hello World\n".green) ;
},
actions: {
"process.stdout.write.done": "HelloName",
".write.err": "@error"
}
},
"HelloName": {
guard: function () {
if (!name || typeof name !== "string")
return "@exit" ;
},
entry: function () {
var str = "Hello "+name+", pleased to meet you.\n" ;
fire.process.stdout.write(str.red) ;
},
actions: {
".write.done": "@exit",
".write.err": "@error"
}
}
}
} ;
}
lnugExample.defaults = {
imports: {
process: process
}
};
module.exports = lnugExample;
Example Output
The source code for the example can be found in the file examples/lnug/lnugExample1.js and run using the ignite command line helper application as follows:
$ ./bin/ignite examples/lnug/lnugExample1.js
Running examples/lnug/lnugExample1.js
Hello World
run: examples/lnug/lnugExample1.js Exited with no error.
$ _
$ ./bin/ignite examples/lnug/lnugExample1.js Steve Running examples/lnug/lnugExample1.js Hello World Hello Steve, pleased to meet you. run: examples/lnug/lnugExample1.js Exited with no error. $ _