+ All Categories
Home > Documents > CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and...

CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and...

Date post: 17-Dec-2015
Category:
Upload: peregrine-small
View: 215 times
Download: 0 times
Share this document with a friend
28
CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1
Transcript
Page 1: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

1

CSCI 3100 Tutorial 3JavaScript amp Nodejs

Presented by SU Yuxin

Department of Computer Science and EngineeringThe Chinese University of Hong Kong

2

Outline

bull Introduction to JavaScriptbull JavaScript Basicbull Advanced Features of JavaScriptbull Introduction to Nodejsbull A Secrethellip

3

Do you know JavaScript

JavaJavaScrip

t

No Relationship

4

What is JavaScript

Script Language

bull Shellbull C

Dynamic

Type

bull Pythonbull Java

Objected-oriented

bull C++bull C

AsynchronousUnique Feature

5

Where to use JavaScript

bull The whole picturebrowser

CSS

HTML

HTML5

JavaScript Server Side

modifycreatedelete

data transmit

bull PHPbull Rails on Rubybull JavaScript

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 2: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

2

Outline

bull Introduction to JavaScriptbull JavaScript Basicbull Advanced Features of JavaScriptbull Introduction to Nodejsbull A Secrethellip

3

Do you know JavaScript

JavaJavaScrip

t

No Relationship

4

What is JavaScript

Script Language

bull Shellbull C

Dynamic

Type

bull Pythonbull Java

Objected-oriented

bull C++bull C

AsynchronousUnique Feature

5

Where to use JavaScript

bull The whole picturebrowser

CSS

HTML

HTML5

JavaScript Server Side

modifycreatedelete

data transmit

bull PHPbull Rails on Rubybull JavaScript

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 3: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

3

Do you know JavaScript

JavaJavaScrip

t

No Relationship

4

What is JavaScript

Script Language

bull Shellbull C

Dynamic

Type

bull Pythonbull Java

Objected-oriented

bull C++bull C

AsynchronousUnique Feature

5

Where to use JavaScript

bull The whole picturebrowser

CSS

HTML

HTML5

JavaScript Server Side

modifycreatedelete

data transmit

bull PHPbull Rails on Rubybull JavaScript

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 4: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

4

What is JavaScript

Script Language

bull Shellbull C

Dynamic

Type

bull Pythonbull Java

Objected-oriented

bull C++bull C

AsynchronousUnique Feature

5

Where to use JavaScript

bull The whole picturebrowser

CSS

HTML

HTML5

JavaScript Server Side

modifycreatedelete

data transmit

bull PHPbull Rails on Rubybull JavaScript

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 5: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

5

Where to use JavaScript

bull The whole picturebrowser

CSS

HTML

HTML5

JavaScript Server Side

modifycreatedelete

data transmit

bull PHPbull Rails on Rubybull JavaScript

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 6: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

6

JavaScript Basic

bull Outputbull Variable amp Arithmeticbull Object amp Arraybull Functionbull IF amp Loop statement

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 7: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

7

JavaScript BasicOutput

bull No printf() bull Use consolelog() alert() instead

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 8: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

8

JavaScript BasicVariable amp Arithmetic

String can be in single or double quotes

Number can be integer or floating point

If there is no initial value the value is undefined

String concatenation

Integer Arithmetic

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 9: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

9

JavaScript BasicObject

You can use any property without declaration

You can also treat function as a property of the object and assign it like this

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 10: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

10

JavaScript BasicArray

Create an array

Initialization

Access an arrayUse it as a dictionary

Multi-type

Build-in functions and properties

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 11: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

11

JavaScript BasicFunction

Declaration

Argument amp Return value

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 12: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

12

JavaScript BasicIF amp Loop statement

IF statement

FOR Loop

WHILE Loop

Note Anything defined will be treat as true Undefined will be treat as false

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 13: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

13

ADVANCED FEATURES

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 14: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

14

Regular Expression

bull First-class citizen in JavaScriptbull Create

var pattern = g$var pattern = new RegExp(ldquog$)

bull UseSoftware Engineeringsearch(pattern)textreplace(javascriptgi JavaScript)1 plus 2 equals 3match(d+g)123456789split()

Any expression ended with letter lsquogrsquo

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 15: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

15

Prototypebull function Range(from to)

thisfrom = from thisto = toRangeprototype = includes function(x) return thisfrom lt= x ampamp x lt= thisto foreach function(f) for(var x = Mathceil(thisfrom) x lt= thisto x++) f(x) toString function() return ( + thisfrom + + thisto + ) Here are example uses of a range objectvar r = new Range(13) Create a range objectrincludes(2) =gt true 2 is in the rangerforeach(consolelog) Prints 1 2 3consolelog(r) Prints (13)

It looks like the definition of class

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 16: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

16

Callback Functionbull function main(callback)

alert(I am main function) alert(Invoke callback function) callback()function b() alert(I am callback function b)function c() alert(I am callback function c)

function test() main(b) main(c)

bull Function is passed as a parameter

bull User-defined behavior at the end of a function or ldquoeventrdquo

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 17: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

17

Advanced Array Methods

bull Other similar functionsndash map()ndash filter()ndash every()ndash some()

Increase Each element by 1dataforEach(function(v i a) a[i] = v + 1)

var data = [12345]compute the sum of the array elementsvar sum = 0dataforEach(function(value) sum += value)consolelog(The sum is + sumtoString())

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 18: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

18

Asynchronous

Synchronously read a file Pass an encoding to get text instead of bytesvar text = fsreadFileSync(configjson utf8) Asynchronously read a binary file Pass a function to get the datafsreadFile(imagepng function(err buffer) if (err) throw err If anything went wrong process(buffer) File contents are in buffer)

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 19: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

19

INTRODUCTION TO NODEJS

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 20: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

20

Where to run my code

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 21: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

21

Where to run my code(conrsquod)

bull Chrome

bull Nodebull $ node testjs

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 22: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

22

IDE Jetbrains WebStorm

httpwwwjetbrainscomwebstorm You can register a student account with your cuhkeduhk email

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 23: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

23

What the Nodejs is designed for

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 24: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

24

Installation and HTTP setup

bull Install Nodejs from httpnodejsorgdownloadbull Use it to create a HTTP serverndash 1 In cmd of Windows type npm install http-server ndashg

bull If you have a HTTP proxy type this firstbull npm config set proxy httpproxycompanycomport

ndash 2 Start HTTP server http-server pathbull The path is the folder you want to share in webbull Your folder must have some files before it works ie indexhtml

(put lsquoit worksrsquo in it)

ndash 3 Open httplocalhost8080 in your browser

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 25: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

25

Modules

httpswwwnpmjscom

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 26: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

26

Event-based Design

var events = require(events)var emitter = new eventsEventEmitter()var username = colinvar password = password an event listeneremitteron(userAdded function(username password) consolelog(Added user + username)) add the user then emit an eventemitteremit(userAdded username password)

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 27: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

27

More details will coming at further tutorial

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip
Page 28: CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.

28

Finally the secret ishellip

bull If you think JavaScript is powerfulhellipbull Butndash Too difficult to learnndash Too complex to writendash Too ugly to read

Try CoffeeScriptReference Google it

  • CSCI 3100 Tutorial 3 JavaScript amp Nodejs
  • Outline
  • Do you know JavaScript
  • What is JavaScript
  • Where to use JavaScript
  • JavaScript Basic
  • JavaScript Basic Output
  • JavaScript Basic Variable amp Arithmetic
  • JavaScript Basic Object
  • JavaScript Basic Array
  • JavaScript Basic Function
  • JavaScript Basic IF amp Loop statement
  • Advanced features
  • Regular Expression
  • Prototype
  • Callback Function
  • Advanced Array Methods
  • Asynchronous
  • Introduction to Nodejs
  • Where to run my code
  • Where to run my code(conrsquod)
  • IDE Jetbrains WebStorm
  • What the Nodejs is designed for
  • Installation and HTTP setup
  • Modules
  • Event-based Design
  • More details will coming at further tutorial
  • Finally the secret ishellip

Recommended