SlideShare a Scribd company logo
MUMPS is dead? Rob Tweed M/Gateway Developments Ltd http://www.mgateway.com Twitter: @rtweed
What is Node.js?
What is Node.js?
What is Node.js? … so what does that mean?
What is Node.js?
What is Node.js? Node.js is a server-side JavaScript environment.
What is Node.js? Node.js is a server-side JavaScript environment. Node.js is a server-side JavaScript interpreter that allows us to handle and make requests via JavaScript: In a web or networked environment
Just Javascript Browsers Node.js server process Javascript Javascript Database
So instead of this: http/ https Persistent connections Browser Browser Browser Web Server (Apache/ IIS) CSP Caché CSP interface Caché CSP interface Your scripts Your data EWD CSP pages
You'd have something like this: Browser Browser Browser Cach é http/ https WebLink interface Cach é CSP interface Child_process connections EWD Runtime Your scripts Your data EWD routines Node.js process Javascript Web server & request/response Handling logic stdin/stdout GT.M or Cach é
What is Node.js?
V8 Node.js uses the Google V8 engine to provide the Javascript environment V8 is the engine in the Chrome browser V8 is  very  fast!
What is Node.js?
What is Node.js? Node.js is a server-side JavaScript environment   that uses an asynchronous event-driven model .
What is Node.js? Node.js is a server-side JavaScript environment   that uses an asynchronous event-driven model . No threads Node.js runs in a single process, handling all client requests Non-blocking I/O Can't wait for slow resources to respond Files, databases, etc Must not block the process or everyone waits
Asynchronous I/O & Javascript Javascript is an ideal language for this No I/O in a browser Access to remote resources is asynchronous The A in Ajax! Send a request for a resource and define a handler to deal with it when it arrives "Call-back function"
Asynchronous I/O & Javascript On the server, in Node.js: Make a request for I/O (file/ database) Define a call-back function Move on immediately When the I/O is complete: Call-back function is fired to handle it
Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = "mydata.txt" open file:"r" use file read buffer // do something with the buffer contents … . // then move on to the next task
Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = "mydata.txt" open file:"r" use file read buffer // do something with the buffer contents … .// at this point the thread is blocked … .// until the buffer contents are read from the file // then move on to the next task
Asynchronous I/O & Javascript The Asynchronous way in Javascript: var fs = require('fs'); fs.readFile('mydata.txt', function (err, buffer) { // Do something with the data in the buffer }); // Immediately execute the next statements //  while it waits for I/O
What is Node.js?
Node.js Evented I/O Node.js is a single process running an event loop When an event occurs, fire a call-back function to handle it When no events are coming in, the Node.js process sits in a dormant state
Node.js process A Node.js process can handle many thousands of clients Provided none of them block Provided none of them do CPU-intensive processing
Node.js / Javascript: popularity Node.js is now the most followed project on Github, exceeding Ruby on Rails Javascript is now the most popular language in the world, based on a number of measures including number of Github projects
Significance for GT.M & Cach é Opportunity to use Javascript as a primary scripting language Global storage for Javascript JSON / Global mapping
Why Javascript? The world's most popular language The world's sexiest, coolest server-side environment Javascript's dynamic interpreted nature has many similarities to MUMPS
Why not MUMPS? Rightly or wrongly, the perception in the mainstream is that the MUMPS language is old-fashioned and inherently broken Daily WTF article: http://thedailywtf.com/Articles/A_Case_of_the_MUMPS.aspx Yet global storage has a great deal to offer as a NoSQL database technology Result: the benefits and advantages of global storage are ignored because modern developers will refuse to learn the language
Making Global Storage Attractive Make it accessible via the coolest, sexiest, most popular language on the planet Demonstrate that global storage is a great NoSQL technology "Universal NoSQL Engine" http://www.mgateway.com/docs/universalNoSQL.pdf
Downside of Node.js Asynchronous programming Callback hell! Deeply nested call-backs Complexity of logic Essential to understand closures 2 main types: Dependent Concurrent Care needed when using for loops to invoke logic that includes callbacks
Dependent callbacks myFunc1(inputs, function(error, results) { var value = results.value; // myFunc2 can't run until myFunc1 returns its results myFunc2(value, function(error, results) { var myResult = results.value; });  });
Concurrent callbacks var count = 0; myFunc1(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc2(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc3(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); // myFunc isn't invoked until all 3 functions are complete // Uses the properties of closures to allow count to be incremented by  // the callbacks in the three functions
Closures Inner functions have access to the outer function's variables, even after the outer function has completed
Closures Inner functions have access to the outer function's variables, even after the outer function has completed  var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log("text = " + text);
Closures Inner functions have access to the outer function's variables, even after the outer function has completed  var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log("text = " + text);
Closures Could be rewritten to use a self-executing function as follows  var digit_name = function() {   var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight', 'nine'];   return function(n) {     return names[n];   }; } () ; // digit_name is the result of running the outer function,  //  so it's a function that takes a value var name = digit_name(3); // name will be 'three'
Downside of Node.js Asynchronous programming Database access functions can't return a value Value is embedded inside the callback Can't chain database functions as objects: document.getElementById('x').parent.firstChild.tagName
Accessing globals from Node.js Cache & GT.M: https://github.com/robtweed/ewdGateway Complete webserver + gateway for EWD Also includes global access functions, eg: get set getJSON mFunction

More Related Content

What's hot (20)

PPT
Server side JavaScript: going all the way
Oleg Podsechin
 
PDF
parenscript-tutorial
tutorialsruby
 
PDF
Node.js
Jan Dillmann
 
PPT
JS everywhere 2011
Oleg Podsechin
 
PPTX
Async and Await on the Server
Doug Jones
 
ODP
Getting started with Perl XS and Inline::C
daoswald
 
PPTX
Node.js - Advanced Basics
Doug Jones
 
PPTX
End to-end async and await
vfabro
 
PDF
Real-Time Web Apps & Symfony. What are your options?
Phil Leggetter
 
PPTX
Async await
Jeff Hart
 
PPTX
introduction to node.js
orkaplan
 
PPTX
Async/Await
Jeff Hart
 
PDF
DaNode - A home made web server in D
Andrei Alexandrescu
 
PPTX
The Road To Reactive with RxJava JEEConf 2016
Frank Lyaruu
 
PPTX
How NOT to write in Node.js
Piotr Pelczar
 
PDF
Scaling Ruby with Evented I/O - Ruby underground
Omer Gazit
 
PDF
Server Side Swift
Jens Ravens
 
PDF
Beyond Fault Tolerance with Actor Programming
Fabio Tiriticco
 
PPTX
CTU June 2011 - C# 5.0 - ASYNC & Await
Spiffy
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
Server side JavaScript: going all the way
Oleg Podsechin
 
parenscript-tutorial
tutorialsruby
 
Node.js
Jan Dillmann
 
JS everywhere 2011
Oleg Podsechin
 
Async and Await on the Server
Doug Jones
 
Getting started with Perl XS and Inline::C
daoswald
 
Node.js - Advanced Basics
Doug Jones
 
End to-end async and await
vfabro
 
Real-Time Web Apps & Symfony. What are your options?
Phil Leggetter
 
Async await
Jeff Hart
 
introduction to node.js
orkaplan
 
Async/Await
Jeff Hart
 
DaNode - A home made web server in D
Andrei Alexandrescu
 
The Road To Reactive with RxJava JEEConf 2016
Frank Lyaruu
 
How NOT to write in Node.js
Piotr Pelczar
 
Scaling Ruby with Evented I/O - Ruby underground
Omer Gazit
 
Server Side Swift
Jens Ravens
 
Beyond Fault Tolerance with Actor Programming
Fabio Tiriticco
 
CTU June 2011 - C# 5.0 - ASYNC & Await
Spiffy
 
Introduction Node.js
Erik van Appeldoorn
 

Similar to Node.js: CAMTA Presentation (20)

ODP
Node js
hazzaz
 
PPTX
Everything you wanted to know about writing async, concurrent http apps in java
Baruch Sadogursky
 
PPTX
hacking with node.JS
Harsha Vashisht
 
ODP
Implementing Comet using PHP
King Foo
 
PPTX
Introduction to node.js
Su Zin Kyaw
 
PDF
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Ran Mizrahi
 
PDF
NodeJS
LinkMe Srl
 
PPTX
Introduction to Node.js
Vikash Singh
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
PDF
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
PPTX
NodeJS
Alok Guha
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PPTX
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Ilya Grigorik
 
PDF
About Node.js
Artemisa Yescas Engler
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PDF
Introduction to Node.js
Richard Lee
 
PDF
Torquebox OSCON Java 2011
tobiascrawley
 
KEY
Introduction to NodeJS with LOLCats
Derek Anderson
 
PPTX
Node.js: A Guided Tour
cacois
 
Node js
hazzaz
 
Everything you wanted to know about writing async, concurrent http apps in java
Baruch Sadogursky
 
hacking with node.JS
Harsha Vashisht
 
Implementing Comet using PHP
King Foo
 
Introduction to node.js
Su Zin Kyaw
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Ran Mizrahi
 
NodeJS
LinkMe Srl
 
Introduction to Node.js
Vikash Singh
 
Writing robust Node.js applications
Tom Croucher
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
NodeJS
Alok Guha
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Ilya Grigorik
 
About Node.js
Artemisa Yescas Engler
 
node.js: Javascript's in your backend
David Padbury
 
Introduction to Node.js
Richard Lee
 
Torquebox OSCON Java 2011
tobiascrawley
 
Introduction to NodeJS with LOLCats
Derek Anderson
 
Node.js: A Guided Tour
cacois
 
Ad

More from Rob Tweed (20)

PDF
QEWD Update
Rob Tweed
 
PPT
Data Persistence as a Language Feature
Rob Tweed
 
PPT
LNUG: Having Your Node.js Cake and Eating It Too
Rob Tweed
 
PPT
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
Rob Tweed
 
PPT
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
Rob Tweed
 
PPT
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
Rob Tweed
 
PPT
QEWD.js, JSON Web Tokens & MicroServices
Rob Tweed
 
PPT
QEWD.js: Have your Node.js Cake and Eat It Too
Rob Tweed
 
PPT
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
Rob Tweed
 
PDF
qewd-ripple: The Ripple OSI Middle Tier
Rob Tweed
 
PPT
EWD 3 Training Course Part 42: The QEWD Docker Appliance
Rob Tweed
 
PDF
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
Rob Tweed
 
PDF
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
Rob Tweed
 
PDF
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
Rob Tweed
 
PDF
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
Rob Tweed
 
PDF
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
Rob Tweed
 
PDF
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
Rob Tweed
 
PDF
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
Rob Tweed
 
PDF
EWD 3 Training Course Part 35: QEWD Session Locking
Rob Tweed
 
PDF
EWD 3 Training Course Part 34: QEWD Resilient Mode
Rob Tweed
 
QEWD Update
Rob Tweed
 
Data Persistence as a Language Feature
Rob Tweed
 
LNUG: Having Your Node.js Cake and Eating It Too
Rob Tweed
 
EWD 3 Training Course Part 45: Using QEWD's Advanced MicroService Functionality
Rob Tweed
 
EWD 3 Training Course Part 44: Creating MicroServices with QEWD.js
Rob Tweed
 
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
Rob Tweed
 
QEWD.js, JSON Web Tokens & MicroServices
Rob Tweed
 
QEWD.js: Have your Node.js Cake and Eat It Too
Rob Tweed
 
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
Rob Tweed
 
qewd-ripple: The Ripple OSI Middle Tier
Rob Tweed
 
EWD 3 Training Course Part 42: The QEWD Docker Appliance
Rob Tweed
 
EWD 3 Training Course Part 41: Building a React.js application with QEWD, Part 5
Rob Tweed
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
Rob Tweed
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
Rob Tweed
 
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
Rob Tweed
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 2
Rob Tweed
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
Rob Tweed
 
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
Rob Tweed
 
EWD 3 Training Course Part 35: QEWD Session Locking
Rob Tweed
 
EWD 3 Training Course Part 34: QEWD Resilient Mode
Rob Tweed
 
Ad

Recently uploaded (20)

PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Introducing and Operating FME Flow for Kubernetes in a Large Enterprise: Expe...
Safe Software
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Practical Applications of AI in Local Government
OnBoard
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Introducing and Operating FME Flow for Kubernetes in a Large Enterprise: Expe...
Safe Software
 
Kubernetes - Architecture & Components.pdf
geethak285
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 

Node.js: CAMTA Presentation

  • 1. MUMPS is dead? Rob Tweed M/Gateway Developments Ltd http://www.mgateway.com Twitter: @rtweed
  • 4. What is Node.js? … so what does that mean?
  • 6. What is Node.js? Node.js is a server-side JavaScript environment.
  • 7. What is Node.js? Node.js is a server-side JavaScript environment. Node.js is a server-side JavaScript interpreter that allows us to handle and make requests via JavaScript: In a web or networked environment
  • 8. Just Javascript Browsers Node.js server process Javascript Javascript Database
  • 9. So instead of this: http/ https Persistent connections Browser Browser Browser Web Server (Apache/ IIS) CSP Caché CSP interface Caché CSP interface Your scripts Your data EWD CSP pages
  • 10. You'd have something like this: Browser Browser Browser Cach é http/ https WebLink interface Cach é CSP interface Child_process connections EWD Runtime Your scripts Your data EWD routines Node.js process Javascript Web server & request/response Handling logic stdin/stdout GT.M or Cach é
  • 12. V8 Node.js uses the Google V8 engine to provide the Javascript environment V8 is the engine in the Chrome browser V8 is very fast!
  • 14. What is Node.js? Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model .
  • 15. What is Node.js? Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model . No threads Node.js runs in a single process, handling all client requests Non-blocking I/O Can't wait for slow resources to respond Files, databases, etc Must not block the process or everyone waits
  • 16. Asynchronous I/O & Javascript Javascript is an ideal language for this No I/O in a browser Access to remote resources is asynchronous The A in Ajax! Send a request for a resource and define a handler to deal with it when it arrives "Call-back function"
  • 17. Asynchronous I/O & Javascript On the server, in Node.js: Make a request for I/O (file/ database) Define a call-back function Move on immediately When the I/O is complete: Call-back function is fired to handle it
  • 18. Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = "mydata.txt" open file:"r" use file read buffer // do something with the buffer contents … . // then move on to the next task
  • 19. Asynchronous I/O & Javascript Synchronous read from a file in MUMPS: set file = "mydata.txt" open file:"r" use file read buffer // do something with the buffer contents … .// at this point the thread is blocked … .// until the buffer contents are read from the file // then move on to the next task
  • 20. Asynchronous I/O & Javascript The Asynchronous way in Javascript: var fs = require('fs'); fs.readFile('mydata.txt', function (err, buffer) { // Do something with the data in the buffer }); // Immediately execute the next statements // while it waits for I/O
  • 22. Node.js Evented I/O Node.js is a single process running an event loop When an event occurs, fire a call-back function to handle it When no events are coming in, the Node.js process sits in a dormant state
  • 23. Node.js process A Node.js process can handle many thousands of clients Provided none of them block Provided none of them do CPU-intensive processing
  • 24. Node.js / Javascript: popularity Node.js is now the most followed project on Github, exceeding Ruby on Rails Javascript is now the most popular language in the world, based on a number of measures including number of Github projects
  • 25. Significance for GT.M & Cach é Opportunity to use Javascript as a primary scripting language Global storage for Javascript JSON / Global mapping
  • 26. Why Javascript? The world's most popular language The world's sexiest, coolest server-side environment Javascript's dynamic interpreted nature has many similarities to MUMPS
  • 27. Why not MUMPS? Rightly or wrongly, the perception in the mainstream is that the MUMPS language is old-fashioned and inherently broken Daily WTF article: http://thedailywtf.com/Articles/A_Case_of_the_MUMPS.aspx Yet global storage has a great deal to offer as a NoSQL database technology Result: the benefits and advantages of global storage are ignored because modern developers will refuse to learn the language
  • 28. Making Global Storage Attractive Make it accessible via the coolest, sexiest, most popular language on the planet Demonstrate that global storage is a great NoSQL technology "Universal NoSQL Engine" http://www.mgateway.com/docs/universalNoSQL.pdf
  • 29. Downside of Node.js Asynchronous programming Callback hell! Deeply nested call-backs Complexity of logic Essential to understand closures 2 main types: Dependent Concurrent Care needed when using for loops to invoke logic that includes callbacks
  • 30. Dependent callbacks myFunc1(inputs, function(error, results) { var value = results.value; // myFunc2 can't run until myFunc1 returns its results myFunc2(value, function(error, results) { var myResult = results.value; }); });
  • 31. Concurrent callbacks var count = 0; myFunc1(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc2(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); myFunc3(inputs, function(error, results) { count++; if (count === 3) myFunc4(inputs); }); // myFunc isn't invoked until all 3 functions are complete // Uses the properties of closures to allow count to be incremented by // the callbacks in the three functions
  • 32. Closures Inner functions have access to the outer function's variables, even after the outer function has completed
  • 33. Closures Inner functions have access to the outer function's variables, even after the outer function has completed var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log("text = " + text);
  • 34. Closures Inner functions have access to the outer function's variables, even after the outer function has completed var digit_name = function() { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function(n) { return names[n]; }; }; var test = digit_name(); // test is a function that takes a value var text = test(3); console.log("text = " + text);
  • 35. Closures Could be rewritten to use a self-executing function as follows var digit_name = function() {  var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight', 'nine'];  return function(n) {    return names[n];  }; } () ; // digit_name is the result of running the outer function, // so it's a function that takes a value var name = digit_name(3); // name will be 'three'
  • 36. Downside of Node.js Asynchronous programming Database access functions can't return a value Value is embedded inside the callback Can't chain database functions as objects: document.getElementById('x').parent.firstChild.tagName
  • 37. Accessing globals from Node.js Cache & GT.M: https://github.com/robtweed/ewdGateway Complete webserver + gateway for EWD Also includes global access functions, eg: get set getJSON mFunction