Index

Symbols

__proto__ property, 4445

+ (plus sign) operator, 28

A

accessing parameters, 262

account signup

Azure, 244

Heroku, 236

adding

pages to applications, 188191

photos to albums, 180181, 186188, 190191

albums

creating, 177179, 183, 188190

finding, 179, 184

listing, 179, 184185

photos

adding, 180181, 186188, 190191

finding, 180, 185186

anonymous functions, 3940

writing with arrow functions, 41

API design, 144145

modifying

for authentication, 198

for database usage, 181

testing, 283286

applications. See web applications

arguments, 37

array literal syntax, 32

arrays, 3235

functions, 3435

arrow functions, 41

this keyword, 5859

assert function, 47

assert module, 280

async module, 104110

asynchronous functions

changing synchronous programming to, 5153

error handling and, 5354

managing

with async module, 104110

problems with, 103104

with promises pattern, 111113

this keyword, 5659

asynchronous looping, 6971, 110

asynchronous tests, 282

authentication, 157160

creating login forms, 160161

flash messages, 162163

logging in, 161

with MySQL, 198

creating login and registration pages, 208211

creating user handlers, 205207

creating users, 199201

fetching users, 201202

implementing, 203204

modifying API, 198

routing in, 207208

updating express application, 202203

restricting page access, 162

auto function, 108110

autogenerated _id fields, searching for, 174

Azure, 244

account signup, 244

applications

cloud storage in, 252256

creating, 247248

deploying, 248

configuring ClearDB add-on, 248252

downloading CLI tools, 244245

logging in, 245246

preparing for deployment, 245247

B

bcrypt module, 200

BDD (behavior-driven development), 277

bitwise operators, 41

blocking IO, 4950

changing to nonblocking IO, 5153

bluebird module, 111113

booleans, 26

bootstrapper (JavaScript), 128129

for login and registration pages, 208211

buffered I/O, 266267

buffers

serving static content, 117120

strings versus, 117

C

caching modules, 94

callback functions

error handling and, 5456

loops and, 7071

this keyword, 5659

Chai, 283

child_process module

exec function, 273274

spawn function, 274276

choosing testing frameworks, 277278

classes, 43

constructors, 91

creating event classes, 121122

prototypes and inheritance, 4345

ClearDB add-on, configuring

in Azure applications, 248252

in Heroku applications, 239241

client-side templates, 122124

adding pages, 188191

with Mustache, 129131

in sample application, 131134

cloning objects, 179

cloud storage

in Azure applications, 252256

in Heroku applications, 241244

Cloudinary

for Azure applications, 252256

for Heroku applications, 241244

collections

creating, 169170

deleting documents, 172

inserting documents, 170171

querying, 172175

updating documents, 171172

command-line scripts. See scripts

comparisons of types, 3637

compressing output, 156157

compute servers, 59

configuration files

creating, 175176

in multiplatform development, 232233

configurations, middleware, 149

configuring ClearDB add-on

in Azure applications, 248252

in Heroku applications, 239241

connecting

to memcached, 226227

to MongoDB databases, 169

in sample application, 176177

to MySQL databases, 195196, 198199

connection pooling, 196

console object, 47

console.error function, 266

console.log function, 266

constants, 24

constructors, 91

control, yielding, 5961

conversions of types, 3637

cookies with express middleware, 153155

cURL, 17

sending POST data, 8283

cwd function, 47

cycles in modules, 9495

D

data structure

in MongoDB, 167

in sample application, 192

data types in MongoDB, 168

databases

MongoDB

connecting to, 169, 176177

creating collections, 169170

creating databases, 169, 176177

data structure, 167

data types, 168

deleting documents from collections, 172

inserting documents into collections, 170171

installing, 165166

low-level operations in sample application, 175181

Node.js usage, 166167

querying collections, 172175

updating documents in collections, 171172

MySQL

authentication, 198211

configuring ClearDB add-on, 239241, 248252

connecting to, 195196, 198199

creating schema, 194195

installing, 193194

Node.js usage, 194

querying, 196197

debugging Node.js, 1821

DELETE method, 156

deleting documents from collections, 172

deploying web applications, 215

to Azure, 244256

basic deployment, 216217

to Heroku, 235244

on Linux/Mac, 218219

multiprocessor deployment, 220223

problems with basic deployment, 218

sessions on multiple servers, 223227

virtual hosting, 227229

on Windows, 219220

development, multiplatform, 232

locations and configuration files, 232233

paths, 233

directories

creating, 264265

listing contents, 265

documentation for modules, 96

documents in collections

deleting, 172

inserting, 170171

updating, 171172

downloading

Azure CLI tools, 244245

Heroku CLI tools, 236

source code, 5

URL contents on Windows, 17

dynos, 235

E

end event, 115

env function, 47

equality operator, 36

error event, 115

error handling, 4546

asynchronous functions and, 5354

callback functions and, 5456

with express, 163164

in web applications, 66

event queues, 52

events

creating event classes, 121122

listeners, 115

exceptions, 4546

exec function, 273274

exit function, 47

express

connecting memcached, 226227

error handling, 163164

HTTPS/SSL support, 230231

installing, 137138

layers in, 139140

middleware, 148

compressing output, 156157

configurations, 149

ordering, 150151

POST data, cookies, sessions, 153155

PUT and DELETE support, 156

static file handling, 151152

usage, 148149

routing in, 140141

for authentication, 207208

updating sample application, 141144

updating for authentication, 202203

virtual hosting support, 227229

web servers, creating, 138139

F

factory functions, 91

fetching users, 201202

file operations in scripts, 263264

files

configuration files, creating, 175176

reading with streams, 116

uploading, 154155

finding

albums, 179, 184

photos, 180, 185186

flash messages, 162163

forEach function, 35, 110

forEachSeries function, 110

for.in loops, 42

forms, receiving POST data, 8687

for.of loops, 42

frameworks for testing

installing Mocha, 283

installing nodeunit, 278

selecting, 277278

fs.open function, 52

fs.read function, 52

fs.readdir function, 6769

fs.readFile function, 128

fs.stat function, 6971

functional tests, 279281

functions

array functions, 3435

arrow functions, 41

this keyword, 5859

asynchronous functions

changing synchronous programming to, 5153

error handling and, 5354

managing with async module, 104110

managing with promises pattern, 111113

problems managing, 103104

this keyword, 5659

callback functions

error handling and, 5456

this keyword, 5659

classes, 43

prototypes and inheritance, 4345

explained, 3740

factory functions, 91

I/O functions

buffered I/O, 266267

readline module, 268273

stdin, stdout, stderr, 266

unbuffered input, 267268

scope, 40

string functions, 2829

synchronous functions, 61, 262

creating directories, 264265

file operations, 263264

listing directory contents, 265

yielding control, 5961

G

GET params, 7982

global object, 46

global variables

console, 47

global, 46

process, 47

groups of tests, 281282

H

handlers

updating in sample application, 182188

user handlers, creating, 205207

help resources, 2122

Heroku, 235236

account signup, 236

applications

cloud storage in, 241244

creating, 238239

testing, 239

configuring ClearDB add-on, 239241

downloading CLI tools, 236

logging in, 236

preparing for deployment, 236238

history of Node.js, 24

HTML skeleton pages, 124125

http module, 17

HTTP POST data. See POST data

HTTP response codes, 79

HTTPS, 229

built-in support for, 230231

generating test certificates, 229230

proxy server support, 231232

I

including modules, 93

indexOf function, 28

–Infinity value, 2526

Infinity value, 2526

inheritance, 4345

input. See also I/O functions

readline module, 268273

unbuffered, 267268

inserting documents into collections, 170171

installing

express, 137138

memcached

on Linux/Mac, 225226

on Windows, 225

Mocha, 283

modules via NPM, 9293

MongoDB, 165166

MySQL, 193194

Node.js

on Linux, 1415

on Mac, 1214

on Windows, 912

nodeunit, 278

instanceof, 45

I/O functions

buffered I/O, 266267

readline module, 268273

stdin, stdout, stderr, 266

unbuffered input, 267268

isArray function, 33

isFinite function, 26

isNaN function, 26

iterable objects, 42

J

JavaScript, 2. See also scripts

bootstrapper, 128129

for login and registration pages, 208211

errors and exceptions, 4546

functions

arrow functions, 41

classes, 43

explained, 3740

prototypes and inheritance, 4345

scope, 40

global variables

console, 47

global, 46

process, 47

MongoDB data structure, 167

operators and constructs, 4142

running Node.js, 16

types

arrays, 3235

booleans, 26

comparisons and conversions, 3637

constants, 24

explained, 2324

numbers, 2526

objects, 3032

strings, 2730

join function, 35

JSON (JavaScript Object Notation), 3031

JSON servers. See also web applications; web servers

API design, 144145

modifying, 181, 198

creating, 6566

L

layers in express, 139140

length property, 27

line-by-line prompting, 269271

Linux

configuration files, 232233

deploying on, 218219

installing memcached, 225226

installing Mocha, 283

installing Node.js, 1415

passing parameters, 262

running scripts, 259260

listeners, 115

listing

albums, 179, 184185

directory contents, 265

listings

adding photos using API, 187188

admin_add_album.html, 189190

admin_add_album.js, 188189

admin_add_photo.js, 190191

album-listing server (load_albums.js), 68

all-node node runner (node_runner.js), 275

another Mustache template page (album.html), 132133

building pages (pages.js), 147

db.js, 198199

express/https module SSL support (https_express_server.js), 230

file loading with full error handling, 56

getting all photos in album, 185186

handling multiple request types, 7376

helper functions (helpers.js), 146147

home page template file (home.html), 131

http-proxy SSL support (https_proxy_server.js), 231

JavaScript page loader (home.js), 128

login page Mustache template (login.html), 211

raw mode on stdin (raw_mode.js), 267268

registration page Mustache template (register.html), 209210

round-robin proxy load balancer (roundrobin.js), 223

rpn.js file, 279280

simple app page bootstrapper (basic.html), 125

simple postfix calculator using readline (readline.js), 269271

static middleware usage (server.js), 152

survey program (questions.js), 272

testing the compute_intersection function, 61

trivial HTTP server, 222

using process#nextTick to be polite, 60

virtual hosts in express (vhost_server.js), 228

load balancers, 221

loading modules, cycles in, 9495

log files, writing to, 216217

logging in, 161

to Azure, 245246

to Heroku, 236

login forms, creating, 160161, 208211

loops, 42

asynchronous looping, 6971, 110

low-level operations, writing in sample application, 175181

M

Macintosh

configuration files, 232233

deploying on, 218219

installing memcached, 225226

installing Mocha, 283

installing Node.js, 1214

passing parameters, 262

running scripts, 259260

managing asynchronous functions

with async module, 104110

problems with, 103104

with promises pattern, 111113

memcached, 224225

connecting to, 226227

installing

on Linux/Mac, 225226

on Windows, 225

messages, flash, 162163

Microsoft Azure. See Azure

middleware, 139, 148

compressing output, 156157

configurations, 149

ordering, 150151

POST data, cookies, sessions, 153155

PUT and DELETE support, 156

static file handling, 151152

usage, 148149

mkdir function, 264

mkdirSync function, 264265

Mocha, 277

installing, 283

testing API design, 283286

modifying API design. See also updating

for authentication, 198

for database usage, 181

modules, 51, 89

assert, 280

async, 104110

bcrypt, 200

bluebird, 111113

caching, 94

child_process

exec function, 273274

spawn function, 274276

documentation, 96

including, 93

installing via NPM, 9293

loading, cycles in, 9495

node-uuid, 200

passport, 157160

authentication with MySQL, 202203

creating login forms, 160161

flash messages, 162163

implementing authentication, 203204

logging in, 161

restricting page access, 162

private package management, 101102

publishing, 102

readline, 268273

returning objects from

constructor model, 91

factory model, 91

in sample application, 146148

searching for, 93

versioning, 94, 97

writing, 8990, 95100

MongoDB

collections

creating, 169170

deleting documents, 172

inserting documents, 170171

querying, 172175

updating documents, 171172

connecting to, 169

in sample application, 176177

data structure, 167

data types, 168

databases, creating, 169, 176177

installing, 165166

Node.js usage, 166167

writing low-level operations in sample application, 175181

multiplatform development, 232

locations and configuration files, 232233

paths, 233

multiple file types, serving in streams, 120121

multiple request types in web applications, 7179

multiprocessor deployment, 220223

sessions and, 223227

Mustache, 124, 129131

MySQL

authentication, 198

creating login and registration pages, 208211

creating user handlers, 205207

creating users, 199201

fetching users, 201202

implementing, 203204

modifying API, 198

routing in, 207208

updating express application, 202203

configuring ClearDB add-on

in Azure applications, 248252

in Heroku applications, 239241

connecting to, 195196, 198199

creating schema, 194195

installing, 193194

Node.js usage, 194

querying, 196197

N

Nan value, 26

nextTick function, 5961

Node shell, 1516

Node.js

debugging, 1821

history of, 24

HTTPS/SSL support, 230231

installing

on Linux, 1415

on Mac, 1214

on Windows, 912

limitations of, 3

resources for information, 2122

running

from JavaScript files, 16

with Node shell, 1516

updating, 2122

nodeunit, 277

installing, 278

writing tests, 278

asynchronous tests, 282

functional tests, 279281

groups of tests, 281282

node-uuid module, 200

nonblocking IO, changing blocking IO to, 5153. See also asynchronous functions

NoSQL. See MongoDB

NPM (Node Package Manager)

installing modules, 9293

private package management, 101102

npm help command, 92

npm install command, 92

npm link command, 101

npm ls command, 93

npm publish command, 102

npm search command, 92

npm unpublish command, 102

npm update command, 93

null, 24

numbers, 2526

O

object literal syntax, 30

objects, 3032

cloning, 179

returning from modules

constructor model, 91

factory model, 91

openSync function, 263

operators, 4142

ordering middleware, 150151

output, compressing, 156157. See also I/O functions

P

packages

NPM. See NPM (Node Package Manager)

updating, 93

page access, restricting, 162

pages

adding to applications, 188191

creating login and registration pages, 208211

paging functionality, 7982

parallel code execution, 107108

parallel function, 107108

parameters, scripts and, 261262

parseFloat function, 26

parseInt function, 26

passing parameters, 261262

passport module, 157160

authentication with MySQL, 202203

creating login forms, 160161

flash messages, 162163

implementing authentication, 203204

logging in, 161

restricting page access, 162

paths in multiplatform development, 233

patterns, 54

asynchronous looping, 6971

callback functions, error handling and, 5456

promises, 111113

photos

adding to albums, 180181, 186188, 190191

finding, 180, 185186

PKG installer, installing Node.js on Mac, 1214

placeholders, 141, 197

pop function, 34

port numbers, 216

POST data

converting to PUT and DELETE, 156

with express middleware, 153155

receiving

via forms, 8687

via streams, 8386

sending, 8283

postfix calculations, 269

precise equality operator, 36

private package management, 101102

process object, 47

processes

blocking IO and, 4950

creating

with exec function, 273274

with spawn function, 274276

process.exit function, 263264

process.nextTick function, 5961

promises pattern, 111113

prompting line-by-line, 269271

prototypes, 4345, 98

proxies

HTTPS/SSL support, 231232

for multiprocessor deployment, 220223

publishing modules, 102

push function, 34

PUT method, 156

Q

query strings, 7982

querying. See also searching

collections, 172175

MySQL databases, 196197

questions/answers with readline module, 271273

quotation marks in strings, 27

R

raw mode, 267

readable event, 115

readdirSync function, 265

reading files with streams, 116

readline module, 268273

Readme.md, 96

readSync function, 263

receiving POST data

via forms, 8687

via streams, 8386

registration pages, creating, 208211

regular expressions, 2930

REPL (Read-Eval-Print-Loop), 1516

replace function, 29

request types, handling multiple, 7179

require function, 51, 93

response codes (HTTP), 79

REST (Representational State Transfer), API design, 144145

restricting page access, 162

returning

data in web applications, 6769

objects from modules

constructor model, 91

factory model, 91

reverse Polish notation, 269

routing

for authentication, 207208

in express, 140141

updating sample application, 141144

running

Node.js

from JavaScript files, 16

with Node shell, 1516

scripts

on Linux/Mac, 259260

on Windows, 260261

S

schemas, creating, 194195

scope of functions, 40

this keyword, 5659

screen utility, 217

scripts

I/O functions

buffered I/O, 266267

readline module, 268273

stdin, stdout, stderr, 266

unbuffered input, 267268

parameters and, 261262

processes

creating with exec function, 273274

creating with spawn function, 274276

running

on Linux/Mac, 259260

on Windows, 260261

synchronous functions, 262

creating directories, 264265

file operations, 263264

listing directory contents, 265

search function, 30

searching. See also querying

for autogenerated _id fields, 174

for modules, 93

securing web applications, 229

built-in support for HTTPS/SSL, 230231

generating test certificates, 229230

proxy server support for HTTPS/SSL, 231232

selecting testing frameworks, 277278

semantic versioning, 4

sending POST data, 8283

serial code execution, 104107

series function, 106107

ServerRequest object, 78

servers

JSON servers

API design, 144145

creating, 6566

modifying API, 181, 198

web application deployment. See web applications, deploying

web servers

creating, 1618

creating in express, 138139

HTML skeleton pages, 124125

JavaScript bootstrapper, 128129

modifying URL scheme, 126128

sessions

with express middleware, 153155

on multiple servers, 223227

setRawMode function, 267

setTimeout function, 51

shebang, 260

shell. See Node shell; REPL (Read-Eval-Print-Loop)

shift function, 34

sort function, 35

source code, downloading, 5

spawn function, 274276

splice function, 28, 34

split function, 29

SQL. See MySQL

SSL, 229

built-in support for, 230231

generating test certificates, 229230

proxy server support, 231232

stability levels, 4

static content

serving with express, 151152

serving with streams, 115

buffers, 117120

modifying URL scheme, 126128

multiple file types, 120121

reading files, 116

in sample application, 125126

stderr, 266. See also error handling

stdin, 266. See also input

stdout, 266

streams

moving data between, 121

receiving POST data, 8386

serving static content, 115

with buffers, 117120

modifying URL scheme, 126128

multiple file types, 120121

reading files, 116

in sample application, 125126

strings, 2730

buffers versus, 117

functions, 2829

regular expressions, 2930

substr function, 28

synchronous functions, 61, 262

creating directories, 264265

file operations, 263264

listing directory contents, 265

synchronous programming, changing to asynchronous programming, 5153

T

TDD (test-driven development), 277

tee utility, 216217

templates, client-side, 122124

adding pages, 188191

with Mustache, 129131

in sample application, 131134

ternary operator, 41

test certificates, generating, 229230

test-driven development (TDD), 277

testing

API design, 283286

frameworks

installing Mocha, 283

installing nodeunit, 278

selecting, 277278

Heroku applications, 239

virtual hosts, 228229

writing tests, 278

asynchronous tests, 282

functional tests, 279281

groups of tests, 281282

this keyword, 5659

threads, blocking IO and, 4950

time function, 47

trim function, 29

try/catch blocks, 46

asynchronous functions and, 5354

typeof, 24, 32

types

arrays, 3235

booleans, 26

comparisons and conversions, 3637

constants, 24

explained, 2324

numbers, 2526

objects, 3032

strings, 2730

U

unbuffered input, 267268

undefined, 24, 33

UNIX. See Linux; Macintosh

unlinkSync function, 264

unshift function, 34

updating. See also modifying API design

documents in collections, 171172

express for authentication, 202203

handlers in sample application, 182188

Node.js, 2122

packages, 93

uploading files, 154155

URL contents

downloading on Windows, 17

modifying URL scheme, 126128

url.parse function, 80

user handlers, creating, 205207

users

authenticating, 206207

creating, 199201, 205206

fetching, 201202

V

variable scope. See scope of functions

verifying Windows installation of Node.js, 1012

versioning of modules, 94, 97

virtual hosting, 227229

W

warn function, 47

waterfall function, 104106

web applications

asynchronous looping, 6971

authentication, 157160

creating login forms, 160161

flash messages, 162163

logging in, 161

restricting page access, 162

client-side templates, 122124

adding pages, 188191

with Mustache, 129131

in sample application, 131134

data structure in sample application, 192

deploying, 215

to Azure, 244256

basic deployment, 216217

to Heroku, 235244

on Linux/Mac, 218219

multiprocessor deployment, 220223

problems with basic deployment, 218

sessions on multiple servers, 223227

virtual hosting, 227229

on Windows, 219220

error handling, 163164

error handling in, 66

limitations of, 12

multiplatform development, 232

locations and configuration files, 232233

paths, 233

multiple request types, 7179

paging functionality, 7982

POST data

receiving via forms, 8687

receiving via streams, 8386

sending, 8283

returning data, 6769

securing with HTTPS/SSL, 229

built-in support for, 230231

generating test certificates, 229230

proxy server support, 231232

updating routing, 141144

web servers. See also JSON servers

creating, 1618

in express, 138139

HTML skeleton pages, 124125

JavaScript bootstrapper, 128129

modifying URL scheme, 126128

static content. See static content

wget, 17

Windows

configuration files, 232233

deploying on, 219220

downloading URL contents, 17

installing memcached, 225

installing Mocha, 283

installing Node.js, 912

passing parameters, 262

running scripts, 260261

writeSync function, 263

writing

to log files, 216217

low-level operations in sample application, 175181

modules, 8990, 95100

tests, 278

asynchronous tests, 282

functional tests, 279281

groups of tests, 281282

Y

yielding control, 5961

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset