SlideShare a Scribd company logo
1 of 25
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Node.js
Quhan Arunasalam
June / 03 / 2015 Hackathon@SST
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
What we’re going to explore today
2
Node.js
NPM
An open source, cross-platform
runtime environment for
server-side Javascript applications.
A package manager for Javascript.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Node.js
Run Javascript on the server
3
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Understanding the Event Loop
The guts of Node
4
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Do
JSON based REST APIs
Web / Mobile-Web Apps
Network Apps
Don’t CPU intensive work
When to use Node?
5
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Test the waters via REPL
The Read-Eval-Print Loop
6
• Provides a way to
interactively run JavaScript
and see the results.
• Useful for debugging, testing,
or just trying things out.
https://www.flickr.com/photos/snype451/5752753663/
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.1: Test the waters via REPL
Read-Eval-Print-Loop
7
$ node
> var a = [1, 2, 3];
> console.log(a);
[ 1, 2, 3 ]
> a.forEach(function (z) { console.log(z); });
1
2
3
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.2: Baby-steps
Building the classic Hello World
8
$ mkdir hello && cd hello
$ touch index.js
// index.js
console.log('Hello SST');
$ node index
Hello SST
https://www.flickr.com/photos/munakz/9228501911/
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
The module system
The building blocks of a Node app
9
http://pixabay.com/en/lego-building-blocks-shapes-puzzle-297773/
• Makes it possible to include
other Javascript files into your
app.
• Helps organize your code into
separate parts with limited
responsibilities.
• Using modules is simple -
You just require() them.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.3: Requiring things
Modifying your previous Hello World example
10
$ touch greet.js
// greet.js
exports.hello = function () {
return 'Hello SST';
}
// index.js
var greet = require('./greet.js');
console.log(greet.hello());
$ node index
Hello SST
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.4: Requiring things (again)
Let’s get bilingual
11
// greet.js
exports.hello = function () {
return 'Hello SST';
}
exports.konbanwa = function () {
return 'Konbanwa SST';
}
// index.js
var greet = require('./greet.js');
console.log(greet.hello());
console.log(greet.konbanwa());
$ node index
Hello SST
Konbanwa SST
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.5: Requiring things (one last time)
Another way of handling exports
12
// greet.js
module.exports = {
hello: function () {
return 'Hello SST';
},
konbanwa: function () {
return 'Konbanwa SST';
}
};
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
In-built modules
Don’t worry, we’re getting to the fun parts
13
http://commons.wikimedia.org/wiki/File:AMC_V8_engine_360_CID_customized_um.JPG
Node ships with a number of
core modules. For example:
• console - Sends output to
stdout or stderr.
• http - Provides a server and
client for HTTP traffic.
• fs - Provides functions to
interact with the file system.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.6: Create a better (Hello) World
By building a web server
14
// index.js
var http = require('http');
var greet = require('./greet.js');
http.createServer(function (req, res) {
res.writeHead(200);
res.end(greet.hello());
}).listen(80);
console.log('Server running at port 80');
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.6: Create a better (Hello) World
Ta-daa!
15
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Reuse and share code
NPM
16
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
What is npm?
It’s 3 things actually
17
https://www.flickr.com/photos/kamshots/3096111340/
• A module registry, containing
a collection of open-source
code.
• A standard, to define
dependencies on other
packages.
• A package manager, for
locally installed modules.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
The npmjs.com registry
Note the 134,726 packages available (at the time of screenshot)
18
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.7: Initializing your Hello World project
With metadata
19
$ npm init
...
name: (hello)
version: (1.0.0)
description: An app to say Hello SST
entry point: (index.js)
test command:
git repository:
keywords: helloworld
author: Quhan Arunasalam
license: (ISC)
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.8: Saving the moment
Installing and using a 3rd party module
20
$ npm install --save moment
// index.js
var http = require('http');
var greet = require('./greet.js');
var moment = require('moment');
http.createServer(function (req, res) {
res.writeHead(200);
res.end('Hi! It is now ' + moment().format('h:mm:ss a'));
}).listen(80);
console.log('Server running at port 80');
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.8: Saving the moment
Ta-daa!
21
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary 22
Figuring out package.json
{
"name": "hello",
"version": "1.0.0",
"description": "An app to say Hello SST",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [
"helloworld"
],
"author": "Quhan Arunasalam",
"license": "ISC",
"dependencies": {
"moment": "^2.9.0"
}
}
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Let’s not publish another hello world
8814 packages available (at the time of screenshot)
23
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Let’s not publish another hello world
Hiding away your little secrets
24
{
"name": "hello",
"version": "1.0.0",
"private": true,
"description": "An app to say Hello SST",
...
}
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
For more information, please contact:
PayPal Singapore
5 Temasek Boulevard #09-01, Suntec Tower Five, Singapore 038985
Quhan Arunasalam

More Related Content

What's hot

Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Fastly
 
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!VMware Tanzu
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARSNAVER D2
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyDavid de Boer
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3Luciano Mammino
 
DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)Soshi Nemoto
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingAlex Derkach
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restartFastly
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Luciano Mammino
 
The top 5 Kubernetes metrics to monitor
The top 5 Kubernetes metrics to monitorThe top 5 Kubernetes metrics to monitor
The top 5 Kubernetes metrics to monitorSysdig
 
Heroku 101 py con 2015 - David Gouldin
Heroku 101   py con 2015 - David GouldinHeroku 101   py con 2015 - David Gouldin
Heroku 101 py con 2015 - David GouldinHeroku
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node jsThomas Roch
 
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...Codemotion
 
手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務Mu Chun Wang
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices ArchitectureIdan Fridman
 

What's hot (20)

Introducing spring
Introducing springIntroducing spring
Introducing spring
 
Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015
 
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and Symfony
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
Tornado in Depth
Tornado in DepthTornado in Depth
Tornado in Depth
 
DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)
 
Zenly - Reverse geocoding
Zenly - Reverse geocodingZenly - Reverse geocoding
Zenly - Reverse geocoding
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restart
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
The top 5 Kubernetes metrics to monitor
The top 5 Kubernetes metrics to monitorThe top 5 Kubernetes metrics to monitor
The top 5 Kubernetes metrics to monitor
 
Heroku 101 py con 2015 - David Gouldin
Heroku 101   py con 2015 - David GouldinHeroku 101   py con 2015 - David Gouldin
Heroku 101 py con 2015 - David Gouldin
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Présentation de HomeKit
Présentation de HomeKitPrésentation de HomeKit
Présentation de HomeKit
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
 
手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 

Similar to Node.js primer

Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE studentsQuhan Arunasalam
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmsom_nangia
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmwilburlo
 
Open Source, infrastructure as Code, Cloud Native Apps 2015
Open Source, infrastructure as Code, Cloud Native Apps 2015Open Source, infrastructure as Code, Cloud Native Apps 2015
Open Source, infrastructure as Code, Cloud Native Apps 2015Jonas Rosland
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budgetDavid Lukac
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...Rob Tweed
 
02 servlet-basics
02 servlet-basics02 servlet-basics
02 servlet-basicssnopteck
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
The Play Framework at LinkedIn
The Play Framework at LinkedInThe Play Framework at LinkedIn
The Play Framework at LinkedInYevgeniy Brikman
 
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...jaxconf
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegelermfrancis
 
01 overview-and-setup
01 overview-and-setup01 overview-and-setup
01 overview-and-setupsnopteck
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsSu Zin Kyaw
 

Similar to Node.js primer (20)

Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Open Source, infrastructure as Code, Cloud Native Apps 2015
Open Source, infrastructure as Code, Cloud Native Apps 2015Open Source, infrastructure as Code, Cloud Native Apps 2015
Open Source, infrastructure as Code, Cloud Native Apps 2015
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
EWD 3 Training Course Part 37: Building a React.js application with ewd-xpres...
 
02 servlet-basics
02 servlet-basics02 servlet-basics
02 servlet-basics
 
Ite express labs
Ite express labsIte express labs
Ite express labs
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
The Play Framework at LinkedIn
The Play Framework at LinkedInThe Play Framework at LinkedIn
The Play Framework at LinkedIn
 
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
 
Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
01 overview-and-setup
01 overview-and-setup01 overview-and-setup
01 overview-and-setup
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 

Node.js primer

  • 1. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Node.js Quhan Arunasalam June / 03 / 2015 Hackathon@SST
  • 2. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary What we’re going to explore today 2 Node.js NPM An open source, cross-platform runtime environment for server-side Javascript applications. A package manager for Javascript.
  • 3. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Node.js Run Javascript on the server 3
  • 4. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Understanding the Event Loop The guts of Node 4
  • 5. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Do JSON based REST APIs Web / Mobile-Web Apps Network Apps Don’t CPU intensive work When to use Node? 5
  • 6. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Test the waters via REPL The Read-Eval-Print Loop 6 • Provides a way to interactively run JavaScript and see the results. • Useful for debugging, testing, or just trying things out. https://www.flickr.com/photos/snype451/5752753663/
  • 7. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.1: Test the waters via REPL Read-Eval-Print-Loop 7 $ node > var a = [1, 2, 3]; > console.log(a); [ 1, 2, 3 ] > a.forEach(function (z) { console.log(z); }); 1 2 3
  • 8. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.2: Baby-steps Building the classic Hello World 8 $ mkdir hello && cd hello $ touch index.js // index.js console.log('Hello SST'); $ node index Hello SST https://www.flickr.com/photos/munakz/9228501911/
  • 9. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary The module system The building blocks of a Node app 9 http://pixabay.com/en/lego-building-blocks-shapes-puzzle-297773/ • Makes it possible to include other Javascript files into your app. • Helps organize your code into separate parts with limited responsibilities. • Using modules is simple - You just require() them.
  • 10. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.3: Requiring things Modifying your previous Hello World example 10 $ touch greet.js // greet.js exports.hello = function () { return 'Hello SST'; } // index.js var greet = require('./greet.js'); console.log(greet.hello()); $ node index Hello SST
  • 11. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.4: Requiring things (again) Let’s get bilingual 11 // greet.js exports.hello = function () { return 'Hello SST'; } exports.konbanwa = function () { return 'Konbanwa SST'; } // index.js var greet = require('./greet.js'); console.log(greet.hello()); console.log(greet.konbanwa()); $ node index Hello SST Konbanwa SST
  • 12. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.5: Requiring things (one last time) Another way of handling exports 12 // greet.js module.exports = { hello: function () { return 'Hello SST'; }, konbanwa: function () { return 'Konbanwa SST'; } };
  • 13. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary In-built modules Don’t worry, we’re getting to the fun parts 13 http://commons.wikimedia.org/wiki/File:AMC_V8_engine_360_CID_customized_um.JPG Node ships with a number of core modules. For example: • console - Sends output to stdout or stderr. • http - Provides a server and client for HTTP traffic. • fs - Provides functions to interact with the file system.
  • 14. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.6: Create a better (Hello) World By building a web server 14 // index.js var http = require('http'); var greet = require('./greet.js'); http.createServer(function (req, res) { res.writeHead(200); res.end(greet.hello()); }).listen(80); console.log('Server running at port 80');
  • 15. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.6: Create a better (Hello) World Ta-daa! 15
  • 16. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Reuse and share code NPM 16
  • 17. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary What is npm? It’s 3 things actually 17 https://www.flickr.com/photos/kamshots/3096111340/ • A module registry, containing a collection of open-source code. • A standard, to define dependencies on other packages. • A package manager, for locally installed modules.
  • 18. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary The npmjs.com registry Note the 134,726 packages available (at the time of screenshot) 18
  • 19. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.7: Initializing your Hello World project With metadata 19 $ npm init ... name: (hello) version: (1.0.0) description: An app to say Hello SST entry point: (index.js) test command: git repository: keywords: helloworld author: Quhan Arunasalam license: (ISC)
  • 20. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.8: Saving the moment Installing and using a 3rd party module 20 $ npm install --save moment // index.js var http = require('http'); var greet = require('./greet.js'); var moment = require('moment'); http.createServer(function (req, res) { res.writeHead(200); res.end('Hi! It is now ' + moment().format('h:mm:ss a')); }).listen(80); console.log('Server running at port 80');
  • 21. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.8: Saving the moment Ta-daa! 21
  • 22. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary 22 Figuring out package.json { "name": "hello", "version": "1.0.0", "description": "An app to say Hello SST", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [ "helloworld" ], "author": "Quhan Arunasalam", "license": "ISC", "dependencies": { "moment": "^2.9.0" } }
  • 23. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Let’s not publish another hello world 8814 packages available (at the time of screenshot) 23
  • 24. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Let’s not publish another hello world Hiding away your little secrets 24 { "name": "hello", "version": "1.0.0", "private": true, "description": "An app to say Hello SST", ... }
  • 25. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. For more information, please contact: PayPal Singapore 5 Temasek Boulevard #09-01, Suntec Tower Five, Singapore 038985 Quhan Arunasalam