SlideShare a Scribd company logo
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Node.js
Quhan Arunasalam
June / 11 / 2015 ITE@PayPal
© 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
Do
JSON based REST APIs
Web / Mobile-Web Apps
Network Apps
Don’t CPU intensive work
When to use Node?
4
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
The module system
The building blocks of a Node app
5
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.1: Requiring things
Building the classic Hello World example
6
Create a folder called hello.
In it, create 2 new files called greet.js and index.js
greet.js
exports.hello = function () {
return 'Hello ITE';
};
index.js
var greet = require('./greet.js');
console.log(greet.hello());
Run the app using node index
Hello ITE
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.2: Requiring things (again)
Let’s get bilingual
7
Modify greet.js
exports.hello = function () {
return 'Hello ITE';
};
exports.konbanwa = function () {
return 'Konbanwa ITE';
};
Modify index.js
var greet = require('./greet.js');
console.log(greet.hello());
console.log(greet.konbanwa());
Run the app using node index
Hello ITE
Konbanwa ITE
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
In-built modules
Don’t worry, we’re getting to the fun parts
8
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.3: Create a better (Hello) World
By building a web server
9
Modify index.js
var http = require('http');
var greet = require('./greet.js');
function server(req, res) {
res.end(greet.hello());
}
http.createServer(server).listen(8000);
console.log('Server running at port 8000');
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.3: Create a better (Hello) World
Ta-daa!
10
* Press Ctrl+C on your Terminal to stop the app
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Reuse and share code
NPM
11
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
What is npm?
It’s 3 things actually
12
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)
13
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.4: Initializing your Hello World project
With metadata
14
Initialize your app with:
npm init
...
name: (hello)
version: (1.0.0)
description: An app to say Hello ITE
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.5: Saving the moment
Installing and using a 3rd party module
15
Install the moment module using:
npm install --save moment
Modify index.js
var http = require('http');
var moment = require('moment');
function server(req, res) {
res.end('It is now ' + moment().format('h:mm:ss a'));
})
http.createServer(server).listen(8000);
console.log('Server running at port 8000');
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary
Lab 2.5: Saving the moment
Ta-daa!
16
* Press Ctrl+C on your Terminal to stop the app
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary 17
Figuring out package.json
{
"name": "hello",
"version": "1.0.0",
"description": "An app to say Hello ITE",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [
"helloworld"
],
"author": "Quhan Arunasalam",
"license": "ISC",
"dependencies": {
"moment": "^2.10.3"
}
}
© 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

PDF
Web Applications with Eclipse RT and Docker in the Cloud
PDF
Eclipse Concierge - an OSGi R5 framework for IoT applications
PPTX
Tamir Dresher - What’s new in ASP.NET Core 6
PDF
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
PDF
CodeIgniter For Project : Workshop 001 - Install Docker and CodeIgniter
PDF
Project Atomic [rootconf2015]
PPTX
Introduction to OSGGi
PDF
CloudKit as a backend
Web Applications with Eclipse RT and Docker in the Cloud
Eclipse Concierge - an OSGi R5 framework for IoT applications
Tamir Dresher - What’s new in ASP.NET Core 6
Java Microservices with Spring Boot and Spring Cloud - Denver JUG 2019
CodeIgniter For Project : Workshop 001 - Install Docker and CodeIgniter
Project Atomic [rootconf2015]
Introduction to OSGGi
CloudKit as a backend

What's hot (19)

PDF
Introduction to node js - From "hello world" to deploying on azure
PDF
Fault Tolerance with Kubernetes
PPTX
Protractor: The Hacker way (NG-MY 2019)
PDF
Ansible Introduction
PDF
Asp.Net Core MVC , Razor page , Entity Framework Core
PDF
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
PDF
Ansible-for-openstack
PPTX
Introduction to .NET Core & ASP.NET Core MVC
PDF
Front-end build tools - Webpack
PPTX
Introduction to ASP.NET Core
PPTX
Luca Relandini - Microservices and containers networking: Contiv, deep dive a...
PPTX
Pod Sandbox workflow creation from Dockershim
PPTX
Controlling multiple VMs with the power of Python
PPTX
Google cloud essential skills challenge lab
PPTX
Ordina SOFTC Presentation - TFS and JAVA, better together
PPTX
Deploy a compute instance with a remote startup script
DOC
Jetty Vs Tomcat
PDF
Kubelet with no Kubernetes Masters | DevNation Tech Talk
PPTX
How to customize Spring Boot?
Introduction to node js - From "hello world" to deploying on azure
Fault Tolerance with Kubernetes
Protractor: The Hacker way (NG-MY 2019)
Ansible Introduction
Asp.Net Core MVC , Razor page , Entity Framework Core
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
Ansible-for-openstack
Introduction to .NET Core & ASP.NET Core MVC
Front-end build tools - Webpack
Introduction to ASP.NET Core
Luca Relandini - Microservices and containers networking: Contiv, deep dive a...
Pod Sandbox workflow creation from Dockershim
Controlling multiple VMs with the power of Python
Google cloud essential skills challenge lab
Ordina SOFTC Presentation - TFS and JAVA, better together
Deploy a compute instance with a remote startup script
Jetty Vs Tomcat
Kubelet with no Kubernetes Masters | DevNation Tech Talk
How to customize Spring Boot?
Ad

Similar to Node.js primer for ITE students (20)

PPTX
Node.js primer
PDF
Node.js Workshop
PPTX
Nodejs web service for starters
DOCX
Basics of node.js
KEY
Dcjq node.js presentation
PPT
Node js
PDF
NodeJS for Beginner
PDF
Practical Node js Building Real World Scalable Web Apps 1st Edition Azat Mard...
PDF
Learning Nodejs For Net Developers Harry Cummings
PDF
Node.js Web Development .pdf
PDF
Learning Node Moving to the Server Side Early Release Shelley Powers 2024 sc...
PDF
Day In A Life Of A Node.js Developer
PDF
Day in a life of a node.js developer
PPTX
Mastering node.js, part 1 - introduction
PPTX
Nodejs
KEY
Practical Use of MongoDB for Node.js
PDF
Jaap : node, npm & grunt
PDF
Node JS Express: Steps to Create Restful Web App
PPTX
A complete guide to Node.js
PDF
Nodejs a-practical-introduction-oredev
Node.js primer
Node.js Workshop
Nodejs web service for starters
Basics of node.js
Dcjq node.js presentation
Node js
NodeJS for Beginner
Practical Node js Building Real World Scalable Web Apps 1st Edition Azat Mard...
Learning Nodejs For Net Developers Harry Cummings
Node.js Web Development .pdf
Learning Node Moving to the Server Side Early Release Shelley Powers 2024 sc...
Day In A Life Of A Node.js Developer
Day in a life of a node.js developer
Mastering node.js, part 1 - introduction
Nodejs
Practical Use of MongoDB for Node.js
Jaap : node, npm & grunt
Node JS Express: Steps to Create Restful Web App
A complete guide to Node.js
Nodejs a-practical-introduction-oredev
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Node.js primer for ITE students

  • 1. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Node.js Quhan Arunasalam June / 11 / 2015 ITE@PayPal
  • 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 Do JSON based REST APIs Web / Mobile-Web Apps Network Apps Don’t CPU intensive work When to use Node? 4
  • 5. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary The module system The building blocks of a Node app 5 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.
  • 6. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.1: Requiring things Building the classic Hello World example 6 Create a folder called hello. In it, create 2 new files called greet.js and index.js greet.js exports.hello = function () { return 'Hello ITE'; }; index.js var greet = require('./greet.js'); console.log(greet.hello()); Run the app using node index Hello ITE
  • 7. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.2: Requiring things (again) Let’s get bilingual 7 Modify greet.js exports.hello = function () { return 'Hello ITE'; }; exports.konbanwa = function () { return 'Konbanwa ITE'; }; Modify index.js var greet = require('./greet.js'); console.log(greet.hello()); console.log(greet.konbanwa()); Run the app using node index Hello ITE Konbanwa ITE
  • 8. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary In-built modules Don’t worry, we’re getting to the fun parts 8 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.
  • 9. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.3: Create a better (Hello) World By building a web server 9 Modify index.js var http = require('http'); var greet = require('./greet.js'); function server(req, res) { res.end(greet.hello()); } http.createServer(server).listen(8000); console.log('Server running at port 8000');
  • 10. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.3: Create a better (Hello) World Ta-daa! 10 * Press Ctrl+C on your Terminal to stop the app
  • 11. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Reuse and share code NPM 11
  • 12. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary What is npm? It’s 3 things actually 12 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.
  • 13. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary The npmjs.com registry Note the 134,726 packages available (at the time of screenshot) 13
  • 14. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.4: Initializing your Hello World project With metadata 14 Initialize your app with: npm init ... name: (hello) version: (1.0.0) description: An app to say Hello ITE entry point: (index.js) test command: git repository: keywords: helloworld author: Quhan Arunasalam license: (ISC)
  • 15. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.5: Saving the moment Installing and using a 3rd party module 15 Install the moment module using: npm install --save moment Modify index.js var http = require('http'); var moment = require('moment'); function server(req, res) { res.end('It is now ' + moment().format('h:mm:ss a')); }) http.createServer(server).listen(8000); console.log('Server running at port 8000');
  • 16. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary Lab 2.5: Saving the moment Ta-daa! 16 * Press Ctrl+C on your Terminal to stop the app
  • 17. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary 17 Figuring out package.json { "name": "hello", "version": "1.0.0", "description": "An app to say Hello ITE", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "keywords": [ "helloworld" ], "author": "Quhan Arunasalam", "license": "ISC", "dependencies": { "moment": "^2.10.3" } }
  • 18. © 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