Hello world - intro to node js

  • View

  • Download

Embed Size (px)


Jeff Andersen from GoInstant Have you ever thought that writing web applications should allow you to use your mad Javascript skillz on the server side as well? Node.js is such a platform. Bundling up the Google Chrome Javascript runtime, Node lets you easily building fast and scalable network applications perfect for the real-time web. It's also a pretty great platform for building basic data driven websites too. Jeff, a web developer at Halifax based GoInstant, will introduce us to the Node platform, exploring it from the ground up.

Text of Hello world - intro to node js


2. Jeff Andersen Developer Twitter: @jeffandersen Email: jeff@goinstant.com 3. What is Node.js? In a nutshell: server-side JavaScriptUsed to build scalable network applicationsBuilt on Googles v8 JavaScript engineEvent-driven, non-blocking (asynchronous) I/O 4. Who uses it? 5. Installing Node.js Visit nodejs.orgDownload the package/installer and runAlternatively: use nvm - Node Version Manager (Similar to Rubys RVM) https://github.com/creationix/nvm 6. Test out the repl From the command line type `node`Type out commands and hit enter 7. Use cases REST APIsStreaming dataHigh concurrencyLeveraging UNIX toolsRealtime applications 8. Event Driven 9. Event Driven 10. Sync vs Async 11. Synchronous (Blocking) 12. Asynchronous (Non-Blocking) 13. Asynchronous (Non-Blocking) Node is built for async i/oSometimes difcult to understandCallback soup 14. Lets run it 15. HTTP Server 16. 5 lines of code Lets run it 17. HTTP Server 18. Community / Ecosystemhttp://notinventedhe.re/on/2011-7-26 19. npmjs.orgOpen source softwareOfcial package manager for Node.jsNearly 55 thousand packages and almost 2.5 million downloads per daypackage.json 20. Package.json 21. npm install 22. Recommended Modules async - Higher-order functions and common patterns for asynchronous codelodash - A utility library delivering consistency, customization, performance, & extras.express - Sinatra inspired web development frameworkmocha - simple, exible, fun test frameworkpg - PostgreSQL clientredis - Redis client 23. Example app 24. Example app Basic REST api 25. What do we need? HTTP serverPostgres databasePostgres clientJSON formatted responses 26. We have an HTTP server 27. Problems? One handler replying to every requestMissing Routing/URL parametersResponse formatting 28. Introducing Express npm install expressSinatra style web frameworkSimple verb-based request handlersFull-featured router body parser, url parameters, query string parsingAutomatic response formatting 29. Same functionality 30. Lets code 31. What could be added? OAuth middleware Middleware: A function that processes a request, typically on an interim basis to the nal request handler.Permissions & token scopesJSON web hooks 32. Twitter recommendations @izs - Isaac Schlueter, Creator of NPM & Node core gate keeper@eranhammer - Eran Hammer, Walmart Labs & OSS contributor@substack - James Halliday, Node module authoring machine@tjholowaychuk - TJ Holowaychuk, Author: Express, Mocha, etc@igrigorik - Ilya Grigorik, Developer advocate at Google@jeresig - John Resig, Creator of jQuery@goinstant - Realtime Collaboration API and Backend