+ (plus sign) operator, 28
accessing parameters, 262
account signup
Azure, 244
Heroku, 236
adding
pages to applications, 188–191
photos to albums, 180–181, 186–188, 190–191
albums
creating, 177–179, 183, 188–190
photos
adding, 180–181, 186–188, 190–191
writing with arrow functions, 41
modifying
for authentication, 198
for database usage, 181
applications. See web applications
arguments, 37
array literal syntax, 32
arrow functions, 41
assert function, 47
assert module, 280
changing synchronous programming to, 51–53
managing
with promises pattern, 111–113
asynchronous looping, 69–71, 110
asynchronous tests, 282
logging in, 161
with MySQL, 198
creating login and registration pages, 208–211
creating user handlers, 205–207
modifying API, 198
updating express application, 202–203
restricting page access, 162
autogenerated _id fields, searching for, 174
Azure, 244
account signup, 244
applications
deploying, 248
configuring ClearDB add-on, 248–252
downloading CLI tools, 244–245
preparing for deployment, 245–247
bcrypt module, 200
BDD (behavior-driven development), 277
bitwise operators, 41
changing to nonblocking IO, 51–53
booleans, 26
bootstrapper (JavaScript), 128–129
for login and registration pages, 208–211
buffers
serving static content, 117–120
strings versus, 117
caching modules, 94
callback functions
Chai, 283
child_process module
choosing testing frameworks, 277–278
classes, 43
constructors, 91
creating event classes, 121–122
prototypes and inheritance, 43–45
ClearDB add-on, configuring
in Azure applications, 248–252
in Heroku applications, 239–241
client-side templates, 122–124
in sample application, 131–134
cloning objects, 179
cloud storage
in Azure applications, 252–256
in Heroku applications, 241–244
Cloudinary
for Azure applications, 252–256
for Heroku applications, 241–244
collections
deleting documents, 172
command-line scripts. See scripts
compute servers, 59
configuration files
in multiplatform development, 232–233
configurations, middleware, 149
configuring ClearDB add-on
in Azure applications, 248–252
in Heroku applications, 239–241
connecting
to MongoDB databases, 169
in sample application, 176–177
to MySQL databases, 195–196, 198–199
connection pooling, 196
console object, 47
console.error function, 266
console.log function, 266
constants, 24
constructors, 91
cookies with express middleware, 153–155
cURL, 17
cwd function, 47
data structure
in MongoDB, 167
in sample application, 192
data types in MongoDB, 168
databases
MongoDB
creating databases, 169, 176–177
data structure, 167
data types, 168
deleting documents from collections, 172
inserting documents into collections, 170–171
low-level operations in sample application, 175–181
updating documents in collections, 171–172
MySQL
configuring ClearDB add-on, 239–241, 248–252
connecting to, 195–196, 198–199
Node.js usage, 194
DELETE method, 156
deleting documents from collections, 172
deploying web applications, 215
multiprocessor deployment, 220–223
problems with basic deployment, 218
sessions on multiple servers, 223–227
development, multiplatform, 232
locations and configuration files, 232–233
paths, 233
directories
listing contents, 265
documentation for modules, 96
documents in collections
deleting, 172
downloading
Heroku CLI tools, 236
source code, 5
URL contents on Windows, 17
dynos, 235
end event, 115
env function, 47
equality operator, 36
error event, 115
asynchronous functions and, 53–54
in web applications, 66
event queues, 52
events
creating event classes, 121–122
listeners, 115
exit function, 47
express
middleware, 148
configurations, 149
POST data, cookies, sessions, 153–155
PUT and DELETE support, 156
updating sample application, 141–144
updating for authentication, 202–203
virtual hosting support, 227–229
web servers, creating, 138–139
factory functions, 91
file operations in scripts, 263–264
files
configuration files, creating, 175–176
reading with streams, 116
finding
forEachSeries function, 110
for.in loops, 42
forms, receiving POST data, 86–87
for.of loops, 42
frameworks for testing
installing Mocha, 283
installing nodeunit, 278
fs.open function, 52
fs.read function, 52
fs.readFile function, 128
functions
arrow functions, 41
asynchronous functions
changing synchronous programming to, 51–53
managing with async module, 104–110
managing with promises pattern, 111–113
callback functions
classes, 43
prototypes and inheritance, 43–45
factory functions, 91
I/O functions
stdin, stdout, stderr, 266
scope, 40
synchronous functions, 61, 262
listing directory contents, 265
global object, 46
global variables
console, 47
global, 46
process, 47
handlers
updating in sample application, 182–188
user handlers, creating, 205–207
account signup, 236
applications
testing, 239
configuring ClearDB add-on, 239–241
downloading CLI tools, 236
logging in, 236
preparing for deployment, 236–238
http module, 17
HTTP POST data. See POST data
HTTP response codes, 79
HTTPS, 229
generating test certificates, 229–230
including modules, 93
indexOf function, 28
input. See also I/O functions
inserting documents into collections, 170–171
installing
memcached
on Windows, 225
Mocha, 283
Node.js
nodeunit, 278
instanceof, 45
stdin, stdout, stderr, 266
isArray function, 33
isFinite function, 26
isNaN function, 26
iterable objects, 42
JavaScript, 2. See also scripts
for login and registration pages, 208–211
functions
arrow functions, 41
classes, 43
prototypes and inheritance, 43–45
scope, 40
global variables
console, 47
global, 46
process, 47
MongoDB data structure, 167
operators and constructs, 41–42
running Node.js, 16
types
booleans, 26
comparisons and conversions, 36–37
constants, 24
join function, 35
JSON (JavaScript Object Notation), 30–31
JSON servers. See also web applications; web servers
length property, 27
line-by-line prompting, 269–271
installing Mocha, 283
passing parameters, 262
listeners, 115
listing
directory contents, 265
listings
adding photos using API, 187–188
album-listing server (load_albums.js), 68
all-node node runner (node_runner.js), 275
another Mustache template page (album.html), 132–133
building pages (pages.js), 147
express/https module SSL support (https_express_server.js), 230
file loading with full error handling, 56
getting all photos in album, 185–186
handling multiple request types, 73–76
helper functions (helpers.js), 146–147
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), 267–268
registration page Mustache template (register.html), 209–210
round-robin proxy load balancer (roundrobin.js), 223
simple app page bootstrapper (basic.html), 125
simple postfix calculator using readline (readline.js), 269–271
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, 94–95
log files, writing to, 216–217
logging in, 161
to Heroku, 236
login forms, creating, 160–161, 208–211
loops, 42
asynchronous looping, 69–71, 110
low-level operations, writing in sample application, 175–181
installing Mocha, 283
passing parameters, 262
managing asynchronous functions
with promises pattern, 111–113
installing
on Windows, 225
Microsoft Azure. See Azure
configurations, 149
POST data, cookies, sessions, 153–155
PUT and DELETE support, 156
mkdir function, 264
Mocha, 277
installing, 283
modifying API design. See also updating
for authentication, 198
for database usage, 181
assert, 280
bcrypt, 200
caching, 94
child_process
documentation, 96
including, 93
node-uuid, 200
authentication with MySQL, 202–203
implementing authentication, 203–204
logging in, 161
restricting page access, 162
private package management, 101–102
publishing, 102
returning objects from
constructor model, 91
factory model, 91
in sample application, 146–148
searching for, 93
collections
deleting documents, 172
connecting to, 169
in sample application, 176–177
data structure, 167
data types, 168
databases, creating, 169, 176–177
writing low-level operations in sample application, 175–181
multiplatform development, 232
locations and configuration files, 232–233
paths, 233
multiple file types, serving in streams, 120–121
multiple request types in web applications, 71–79
multiprocessor deployment, 220–223
authentication, 198
creating login and registration pages, 208–211
creating user handlers, 205–207
modifying API, 198
updating express application, 202–203
configuring ClearDB add-on
in Azure applications, 248–252
in Heroku applications, 239–241
connecting to, 195–196, 198–199
Node.js usage, 194
Nan value, 26
Node.js
installing
limitations of, 3
resources for information, 21–22
running
from JavaScript files, 16
nodeunit, 277
installing, 278
writing tests, 278
asynchronous tests, 282
node-uuid module, 200
nonblocking IO, changing blocking IO to, 51–53. See also asynchronous functions
NoSQL. See MongoDB
private package management, 101–102
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
object literal syntax, 30
cloning, 179
returning from modules
constructor model, 91
factory model, 91
openSync function, 263
output, compressing, 156–157. See also I/O functions
packages
NPM. See NPM (Node Package Manager)
updating, 93
page access, restricting, 162
pages
adding to applications, 188–191
creating login and registration pages, 208–211
parallel code execution, 107–108
parameters, scripts and, 261–262
parseFloat function, 26
parseInt function, 26
authentication with MySQL, 202–203
implementing authentication, 203–204
logging in, 161
restricting page access, 162
paths in multiplatform development, 233
patterns, 54
callback functions, error handling and, 54–56
photos
adding to albums, 180–181, 186–188, 190–191
PKG installer, installing Node.js on Mac, 12–14
pop function, 34
port numbers, 216
converting to PUT and DELETE, 156
with express middleware, 153–155
receiving
postfix calculations, 269
precise equality operator, 36
private package management, 101–102
process object, 47
processes
creating
process.exit function, 263–264
process.nextTick function, 59–61
prompting line-by-line, 269–271
proxies
for multiprocessor deployment, 220–223
publishing modules, 102
push function, 34
PUT method, 156
querying. See also searching
questions/answers with readline module, 271–273
quotation marks in strings, 27
raw mode, 267
readable event, 115
readdirSync function, 265
reading files with streams, 116
Readme.md, 96
readSync function, 263
receiving POST data
registration pages, creating, 208–211
REPL (Read-Eval-Print-Loop), 15–16
replace function, 29
request types, handling multiple, 71–79
response codes (HTTP), 79
REST (Representational State Transfer), API design, 144–145
restricting page access, 162
returning
data in web applications, 67–69
objects from modules
constructor model, 91
factory model, 91
reverse Polish notation, 269
routing
updating sample application, 141–144
running
Node.js
from JavaScript files, 16
scripts
scope of functions, 40
screen utility, 217
I/O functions
stdin, stdout, stderr, 266
processes
creating with exec function, 273–274
creating with spawn function, 274–276
running
synchronous functions, 262
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, 230–231
generating test certificates, 229–230
proxy server support for HTTPS/SSL, 231–232
selecting testing frameworks, 277–278
semantic versioning, 4
serial code execution, 104–107
ServerRequest object, 78
servers
JSON servers
web application deployment. See web applications, deploying
web servers
JavaScript bootstrapper, 128–129
sessions
with express middleware, 153–155
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
split function, 29
SQL. See MySQL
SSL, 229
generating test certificates, 229–230
stability levels, 4
serving with streams, 115
reading files, 116
in sample application, 125–126
stderr, 266. See also error handling
stdout, 266
streams
moving data between, 121
serving static content, 115
reading files, 116
in sample application, 125–126
buffers versus, 117
substr function, 28
synchronous functions, 61, 262
listing directory contents, 265
synchronous programming, changing to asynchronous programming, 51–53
TDD (test-driven development), 277
templates, client-side, 122–124
in sample application, 131–134
ternary operator, 41
test certificates, generating, 229–230
test-driven development (TDD), 277
testing
frameworks
installing Mocha, 283
installing nodeunit, 278
Heroku applications, 239
writing tests, 278
asynchronous tests, 282
threads, blocking IO and, 49–50
time function, 47
trim function, 29
try/catch blocks, 46
asynchronous functions and, 53–54
types
booleans, 26
comparisons and conversions, 36–37
constants, 24
unlinkSync function, 264
unshift function, 34
updating. See also modifying API design
documents in collections, 171–172
express for authentication, 202–203
handlers in sample application, 182–188
packages, 93
URL contents
downloading on Windows, 17
url.parse function, 80
user handlers, creating, 205–207
users
variable scope. See scope of functions
verifying Windows installation of Node.js, 10–12
warn function, 47
logging in, 161
restricting page access, 162
client-side templates, 122–124
in sample application, 131–134
data structure in sample application, 192
deploying, 215
multiprocessor deployment, 220–223
problems with basic deployment, 218
sessions on multiple servers, 223–227
error handling in, 66
multiplatform development, 232
locations and configuration files, 232–233
paths, 233
POST data
securing with HTTPS/SSL, 229
generating test certificates, 229–230
web servers. See also JSON servers
JavaScript bootstrapper, 128–129
static content. See static content
wget, 17
Windows
downloading URL contents, 17
installing memcached, 225
installing Mocha, 283
passing parameters, 262
writeSync function, 263
writing
low-level operations in sample application, 175–181
tests, 278
asynchronous tests, 282