Node.js #digpen presentation
Upcoming SlideShare
Loading in...5

Node.js #digpen presentation



JavaScript from Client to Server and Beyond!

JavaScript from Client to Server and Beyond!



Total Views
Views on SlideShare
Embed Views



6 Embeds 226 108 74
http://localhost 23 18 2 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Node.js #digpen presentation Node.js #digpen presentation Presentation Transcript

  • Node.js:JavaScript from Client to Server and Beyond! Robert McCarthy –CEO Gary Ratclliffe – Development Manager
  • Agenda1. The best new technology in the world2. The exciting future3. The real world4. If still alive Goto 1 2
  • Introduction to GOSSRobert McCarthy – GOSS CEO Gary Ratclliffe – Technical
  • Who we work with 4
  • Server-side Javascript 5
  • How many of you use JavaScript? Put your hands UP if YES Is the majority of your JavaScript jQuery? Put your hands DOWN if YESAre you using any server-side JavaScript? Put yours hands DOWN if NO 6
  • Why? 7
  • The Problem? 9
  • Form validation for websites User needs simple validation 10
  • On the browser/^[A-D][0-9]{4}$/i.test(v) 11
  • On the server CF: ReFindNoCase("^[A-D][0-9]{4}$", v) GT 0 Java: Pattern.matches("(?i)^[A-D][0-9]{4}$", v).NET Regex.Match(v, "^[A-D][0-9]{4}$", RegexOptions.IgnoreCase) 12
  • 4 different implementations!! More work, more maintenance, more risk 13
  • The Solution?Server Side javascript = One languageLess work, less maintenance, less risk 14
  • The Implementation Java Mozilla Rhino SiteBrowser CF Site /^[A-D][0-9]{4}$/i.test(v) .NET Site MS Jscript 15
  • What Next?Like the idea of common language on all platforms(But Clients still expect .NET sites to be .NET like & Java sites to be Java like) 16
  • Entire Forms engine? Complex Benefits from implementing once Needs to be extensible There is always a new requirements Clients could create their own extensions 17
  • So we did it!Forms generated using a simple template* containing JavaScript<%if ( Props["FIELDPROPERTIES"]["MAXLENGTH"] !== "") { maxLength="maxlength=" + Props["FIELDPROPERTIES"]["MAXLENGTH"] + "";}%><label for=<%=Props["FIELDID"]%>><%=Processor.htmlEsc(Props["FIELDPROPERTIES"]["LABEL"])%></label><input type="text" name="<%=Props["FIELDID"]%>" id="<%=Props["FIELDID"]%>" <%=maxLength%>/> 18
  • SnagWe really needed a good, fast JavaScript engine on all platforms. JScript was problem 19
  • V8 Arrives! Created by Google for ChromeAlso designed to be used in other apps 20
  • V8 is FAST!!Clever optimisations and compiling to native code.Not quite as dramatic now as when it first appeared 21
  • V8 is Single Threaded!!Only one thread can execute JavaScript at a timeV8 Locking can help synchronize multiple threads One of reasons it’s fast Multi-threading can get complex…and slow 22
  • wrapperReplaced JScript with JavaScript .NET from Noesis Proved reliable in production deployment Real JavaScript Much faster than Jscript!! 23
  • V8 is Single Threaded!! A problem for traditional server-side scalabilityHow do you handle multiple concurrent requests? 24
  • wrapper Limited by single threading Resorted to a global lock around executionBut an evolutionary dead-end while V8 is single threaded 25
  • Along came Node.JS 26
  • Along came Node.JS 27
  • Non blocking vs Threads Threads use a lot of memory and are limitedUse asynchronous IO and an event loop like NGINX 28
  • Weakness now a strengthRyan Dahl, creator of Node.JS used these concepts in Node.JS The single threaded nature of V8 was no longer a problem 29
  • You’ve gotta love it 30
  • Node.JS
  • What can Node.js do? Simple http hello world 32
  • Simple web server Continuations break processing into steps Function called on each requestFunction called when file contents available 33
  • Node.JS Lots of additional modulesReally learn JavaScript the language not just jQuery Google ‘Douglas Crockford’ Look at source code of real projects Combine it with MongoDB for end-to-end JSON 34
  • Node.JSThink carefully if your application needs it Highly interactive? Loads of AJAX? Very high number of requests? Not just because you can! 35
  • 1000’s of concurrent requests All server-side JavaScript
  • Writing continuations for everything is hardSooner or later something has to do something
  • Writing continuations for everything is hard 38
  • Real world code is hard How many developers really understand it? Many can tweak, but starting from scratch…Debugging can be difficult Node-inspector worth a look 39
  • Our SolutionLets call it pragmatic 40
  • IcedCoffeeScript? Not a drink but derived from coffeesriptCoffeeScript = Cool, elegant syntax, JavaScript without the Bad Bits 41
  • IcedCoffeeScript?What happen to the 1 language It makes you think different. 42
  • await and defer used to express callbacksCleaner code layout but you do have to learn CoffeeScript Extra build step to generate JavaScript 43
  • And that other issue? 44
  • Sooner or later something has to do something For many things this is not a problem eg Database modules written to be asynchronous 45
  • Non blocking? This example is computationally intensive. It results in high CPU use on any system. On Node.JS it would only process one request at a time. n=40 takes about 5s 3 concurrent requests: 1 client will wait 15s 46
  • V8 is single threaded!A badly written extension and Bye Bye server… 47
  • Use Node.JS for it’s strengths 48
  • Multiple workers processes JavaScript Worker JavaScript Worker JavaScript Worker TeaJS TeaJS TeaJS Worker Manager Node.JS Java Worker Requests Java Worker Java Worker Java VM Java VM Management Java VM Security Node.JS Worker Node.JS Worker Node.JS Worker Node.JS Node.JS Node.JS 49
  • Best of all worlds Requests delegated to a suitable worker or queued if worker busyA CGI style wrapper round the V8 engine allowing use of traditional linear JavaScript. It’s a good match for our approach to forms rendering 50
  • Where Next? Does the industry need Node.JS?Other web servers can/will achieve similar performance So its really all about the language? 51
  • Is 1 Language an ideal? Same developers for UI and Backend? Common in start-ups Less so in the ‘enterprise’ Jack of all trades master of none? 52
  • So will it survive? 53
  • Today most sites.. 54
  • Multiple Dev Languages 55
  • Client is a dumb browser 56
  • Clients are isolated from one another 57
  • Anything more interactive tends to be bespoke 58
  • Imagine 60
  • ImagineOne server-side infrastructure 61
  • ImagineOne Language 62
  • ImagineOne Data Format: JSON? 63
  • ImagineTransfer Data not UI 64
  • ImagineCollaborate & Distribute 65
  • 66
  • So is it just a dream? 67
  • 68
  • But that’s for the next talk? 69
  • Final Thoughts…. The web is changing at pace. There will be lots of shiny toys They might not lead to nirvanabut they will often give you a glimpse of a very exciting future!! Stay Excited… 70
  • Any questions? Thank you!!PS. We are hiring!