SlideShare a Scribd company logo
1 of 30
Intro to Node.js
        Chris Cowan
            Lead Engineer
    http://www.plus3network.com
What is Node.js?
•   Create by Ryan Dahl
•   Uses Chrome’s V8 Engine
•   Uses Non-Blocking I/O
•   Single Threaded
•   Server Side JavaScript
•   Active Community
Node’s Goal is to provide an
 easy way to build scalable
    network programs.
Node.js is NOT another
  web framework!

  But you can create a web framework using NPM modules.
Node.js is…
             Web Server
              TCP Server
     Awesome Robot Controller
     Command Line Application
            Proxy Server
          Streaming Server
          VoiceMail Server
Anything that has to deal with high I/O
Node.js is
Server Side JavaScript!
Why Node.js?
• Non Blocking I/O
• Based on Chrome’s V8 Engines (FAST!)
• 15,000+ Modules
• Active Community (IRC, Mailing Lists, Twitter,
  Github)
• Mac, Linux and Windows (all first class citizens)
• One Language for Frontend and Backend
• JavaScript is the Language of the Web
Installing Node.js
Mac OS X
1. Go to http://nodejs.org and click install
2. Install the downloaded package

Windows
1. Go to http://nodejs.org and click install
2. Install the downloaded package

Linux (and *nix variants)
1. Go to http://nodejs.org and click install
2. Decompress source and… ./configure … make … make install
   ( for Ubuntu use Chris Lea’s PPA – ppa:chris-lea/node.js )
Some Basic
 Examples
Hello World
Create hello-world.js
console.log(‘Hello World’);

On the command line run
node hello-world.js

You should see
Hello World
Basic HTTP Server




 *Running this script my development box,
 I can achieve 10,000+ requests per second
      with 100 concurrent connections
          without breaking a sweat
Some people use the
 core http module to
build their web apps,
most use a framework
     like Express
 or Connect or Flatiron or Tako or Derby or Geddy or Mojito or …
Visit
http://expressjs.com/guide.html
       for a detailed guide
         on using Express
What is Non-Blocking I/O?
    And why should I care?
Blocking I/




270ms = SUM(user, activities, leaderboard)
Non-Blocking I/




150ms = MAX(user, activities, leaderboard)
The most jarring thing
about Server Side JavaScript
  is thinking in callbacks
Callbacks are the Devil’s Work!
         Don’t go down this rabbit hole…




One of the biggest mistakes is to get yourself in
 to callback hell by nesting callbacks inside of
       callbacks inside of more callbacks.
Avoiding Callback Hell
• Keep your code shallow
• Break up your code into small chunks
• Use a sequential library like async
• Visit http://callbackhell.com
Async to the rescue!
Async provides several useful
 patterns for asynchronous control
  flow including: parallel, series,
     waterfall, auto and queue.

                      Visit
        https://github.com/caolan/async
for a detailed guide on using the async module.
The Node Package Manager
 otherwise know as… NPM

 It’s how you harness the
    awesomeness of the
    Node.js community!
Using NPM
It’s standard practice to install modules locally for your current project.
Modules are installed in the ./node_modules in the current directory.

To Install a new module

npm install <module>

To find a module in the NPM repository

npm search <search string>

To list the modules (and their dependencies) in the current project

npm list

To see module details

npm info <module>
DON’T INSTALL
MODULES GLOBALLY!
 Unless they are tools like node-dev, jake, express, minify-js
  OR linked development modules but more on that later.
NPM is awesome sauce!

               Visit
        https://npmjs.org
for more details about NPM and to
browse the current NPM Repository
Creating your own modules
• Node.js uses CommonJS Modules
• require(‘./example’) will load either
  example.js or example/index.js or the entry
  point specified in package.json
• Run npm init to bootstrap your new module
• Try to stick to creating Pure JavaScript
  modules if possible. It will give you less
  headaches down the road.
Basic Module Example
Everything exposed via module.exports is available as an instance variable.




Once you’ve created a module you use it like this…




Keep this in mind… modules are loaded once and cached. So when
you load the module a second time in your app, require just
returns the cache copied. This lets you do interesting things…
Installing your module
• Run npm link in the module working directory
• Then run npm link <module> in the your project
  folder to link it from the global module to your
  local node_modules.

• OR you can create a private registry
  (See https://npmjs.org/doc/registry.html)

• OR just link it by hand :P
My Favorite Modules
• request      • jake
• async        • hogan.js
• node-dev     • connect
• underscore   • moment
• express      • mysql
Questions?
Contact me at chris@chriscowan.us

More Related Content

What's hot

Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdfBareen Shaikh
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
An Introduction to WebAssembly
An Introduction to WebAssemblyAn Introduction to WebAssembly
An Introduction to WebAssemblyDaniel Budden
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.jsNodejsFoundation
 
NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA Pramendra Gupta
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 

What's hot (20)

Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
An Introduction to WebAssembly
An Introduction to WebAssemblyAn Introduction to WebAssembly
An Introduction to WebAssembly
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node ppt
Node pptNode ppt
Node ppt
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Swoole Love PHP
Swoole Love PHPSwoole Love PHP
Swoole Love PHP
 
Node js
Node jsNode js
Node js
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Express JS
Express JSExpress JS
Express JS
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
 
NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA  NextJS, A JavaScript Framework for building next generation SPA
NextJS, A JavaScript Framework for building next generation SPA
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 

Viewers also liked

Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSRoss Kukulinski
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsBudh Ram Gurung
 
Vagrant plugin development intro
Vagrant plugin development introVagrant plugin development intro
Vagrant plugin development introBudh Ram Gurung
 

Viewers also liked (8)

Philly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
 
Build App with Nodejs - YWC Workshop
Build App with Nodejs - YWC WorkshopBuild App with Nodejs - YWC Workshop
Build App with Nodejs - YWC Workshop
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
Best node js course
Best node js courseBest node js course
Best node js course
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications
 
Vagrant plugin development intro
Vagrant plugin development introVagrant plugin development intro
Vagrant plugin development intro
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 

Similar to Intro to Node.js (v1)

Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Mongo and node mongo dc 2011
Mongo and node mongo dc 2011Mongo and node mongo dc 2011
Mongo and node mongo dc 2011async_io
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platformSreenivas Kappala
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jibanJibanananda Sana
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.jsKasey McCurdy
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JSJacob Nelson
 
Node js presentation
Node js presentationNode js presentation
Node js presentationshereefsakr
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Ganesh Kondal
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10David Ashton
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentIrfan Maulana
 
Irfan maulana nodejs web development
Irfan maulana   nodejs web developmentIrfan maulana   nodejs web development
Irfan maulana nodejs web developmentPHP Indonesia
 
An Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureAn Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureTroy Miles
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting startedTriet Ho
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentationasync_io
 
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...Introducing Vert.x 2.0 - Taking polyglot application development to the next ...
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...jaxLondonConference
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGrant Goodale
 

Similar to Intro to Node.js (v1) (20)

Node.js
Node.jsNode.js
Node.js
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
Mongo and node mongo dc 2011
Mongo and node mongo dc 2011Mongo and node mongo dc 2011
Mongo and node mongo dc 2011
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
Irfan maulana nodejs web development
Irfan maulana   nodejs web developmentIrfan maulana   nodejs web development
Irfan maulana nodejs web development
 
An Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureAn Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows Azure
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...Introducing Vert.x 2.0 - Taking polyglot application development to the next ...
Introducing Vert.x 2.0 - Taking polyglot application development to the next ...
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
 

Recently uploaded

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governanceWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Intro to Node.js (v1)

  • 1. Intro to Node.js Chris Cowan Lead Engineer http://www.plus3network.com
  • 2. What is Node.js? • Create by Ryan Dahl • Uses Chrome’s V8 Engine • Uses Non-Blocking I/O • Single Threaded • Server Side JavaScript • Active Community
  • 3. Node’s Goal is to provide an easy way to build scalable network programs.
  • 4. Node.js is NOT another web framework! But you can create a web framework using NPM modules.
  • 5. Node.js is… Web Server TCP Server Awesome Robot Controller Command Line Application Proxy Server Streaming Server VoiceMail Server Anything that has to deal with high I/O
  • 7. Why Node.js? • Non Blocking I/O • Based on Chrome’s V8 Engines (FAST!) • 15,000+ Modules • Active Community (IRC, Mailing Lists, Twitter, Github) • Mac, Linux and Windows (all first class citizens) • One Language for Frontend and Backend • JavaScript is the Language of the Web
  • 8. Installing Node.js Mac OS X 1. Go to http://nodejs.org and click install 2. Install the downloaded package Windows 1. Go to http://nodejs.org and click install 2. Install the downloaded package Linux (and *nix variants) 1. Go to http://nodejs.org and click install 2. Decompress source and… ./configure … make … make install ( for Ubuntu use Chris Lea’s PPA – ppa:chris-lea/node.js )
  • 10. Hello World Create hello-world.js console.log(‘Hello World’); On the command line run node hello-world.js You should see Hello World
  • 11. Basic HTTP Server *Running this script my development box, I can achieve 10,000+ requests per second with 100 concurrent connections without breaking a sweat
  • 12. Some people use the core http module to build their web apps, most use a framework like Express or Connect or Flatiron or Tako or Derby or Geddy or Mojito or …
  • 13. Visit http://expressjs.com/guide.html for a detailed guide on using Express
  • 14. What is Non-Blocking I/O? And why should I care?
  • 15. Blocking I/ 270ms = SUM(user, activities, leaderboard)
  • 16. Non-Blocking I/ 150ms = MAX(user, activities, leaderboard)
  • 17. The most jarring thing about Server Side JavaScript is thinking in callbacks
  • 18. Callbacks are the Devil’s Work! Don’t go down this rabbit hole… One of the biggest mistakes is to get yourself in to callback hell by nesting callbacks inside of callbacks inside of more callbacks.
  • 19. Avoiding Callback Hell • Keep your code shallow • Break up your code into small chunks • Use a sequential library like async • Visit http://callbackhell.com
  • 20. Async to the rescue!
  • 21. Async provides several useful patterns for asynchronous control flow including: parallel, series, waterfall, auto and queue. Visit https://github.com/caolan/async for a detailed guide on using the async module.
  • 22. The Node Package Manager otherwise know as… NPM It’s how you harness the awesomeness of the Node.js community!
  • 23. Using NPM It’s standard practice to install modules locally for your current project. Modules are installed in the ./node_modules in the current directory. To Install a new module npm install <module> To find a module in the NPM repository npm search <search string> To list the modules (and their dependencies) in the current project npm list To see module details npm info <module>
  • 24. DON’T INSTALL MODULES GLOBALLY! Unless they are tools like node-dev, jake, express, minify-js OR linked development modules but more on that later.
  • 25. NPM is awesome sauce! Visit https://npmjs.org for more details about NPM and to browse the current NPM Repository
  • 26. Creating your own modules • Node.js uses CommonJS Modules • require(‘./example’) will load either example.js or example/index.js or the entry point specified in package.json • Run npm init to bootstrap your new module • Try to stick to creating Pure JavaScript modules if possible. It will give you less headaches down the road.
  • 27. Basic Module Example Everything exposed via module.exports is available as an instance variable. Once you’ve created a module you use it like this… Keep this in mind… modules are loaded once and cached. So when you load the module a second time in your app, require just returns the cache copied. This lets you do interesting things…
  • 28. Installing your module • Run npm link in the module working directory • Then run npm link <module> in the your project folder to link it from the global module to your local node_modules. • OR you can create a private registry (See https://npmjs.org/doc/registry.html) • OR just link it by hand :P
  • 29. My Favorite Modules • request • jake • async • hogan.js • node-dev • connect • underscore • moment • express • mysql
  • 30. Questions? Contact me at chris@chriscowan.us