GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add changes :seedling: · Bujhm/fullstack-javascript@e31537e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • chapter5
    • chapter5.md
  • chapter6
    • chapter6.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎chapter5/chapter5.md‎

Copy file name to clipboardExpand all lines: chapter5/chapter5.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ CHAPTER 5
44

55
Backbone.js and Parse
66
=========================
7-
> *Java is to JavaScript what Car is to Carpet.*
7+
> *When in doubt—console log.*
88
>
9-
> — [Chris Heilmann](http://christianheilmann.com)
9+
> — [Azat Mardan](http://azat.co)
1010
1111
In this chapter, we'll explore the practical aspect of leveraging
1212
Parse for a Backbone.js app. The chapter will illustrate the following:
Collapse file

‎chapter6/chapter6.md‎

Copy file name to clipboardExpand all lines: chapter6/chapter6.md
+94-115Lines changed: 94 additions & 115 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,25 @@ Intro to Node.js
1313
In this chapter, we'll cover the following:
1414

1515
- Building "Hello World" in Node.js
16-
17-
- Node.js Core Modules
18-
19-
- npm Node Package Manager
20-
21-
- Message Board with Node.js: Memory Store Version
22-
23-
- Unit Testing Node.js
16+
- Node.js core modules
17+
- npm Node package manager
18+
- Message Board with Node.js: memory store version
19+
- Unit testing Node.js
2420

2521
Node.js is a non-blocking platform for building web applications. It
26-
uses JavaScript, so it's a centerpiece in our fullstack JavaScript
27-
development. We'll start with Hello World and cover core modules and
28-
npm. Then, we deploy our Hello World app to cloud.
22+
uses JavaScript, so it's a centerpiece in our full stack JavaScript
23+
development. We'll start by building our "Hello World" app and then we'll cover core modules and
24+
npm. Then, we deploy our "Hello World" app to the cloud.
2925

3026
Building "Hello World" in Node.js
3127
=================================
3228

33-
<span id="OLE_LINK27" class="anchor"><span id="OLE_LINK26"
34-
class="anchor"><span id="OLE_LINK36" class="anchor"><span
35-
id="OLE_LINK38" class="anchor"><span id="OLE_LINK39"
36-
class="anchor"><span id="buildinghelloworld"
37-
class="anchor"></span></span></span></span></span></span>Supplemental
38-
video which walks you through the implementation and demonstrates the
39-
project: http://bit.ly/1QnqFmF.
40-
4129
To check if you have Node.js installed on your computer, type and
4230
execute this command in your terminal:
4331

4432
$ node -v
4533

46-
As of this writing, the latest version is 8.11.1. If you don't have
47-
Node.js installed, or if your version is behind, you can download the
48-
latest version at [nodejs.org/#download](http://nodejs.org/#download).
34+
Get the version 8 or higher. If you don't have Node.js installed, or if your version is older (behind or lower), you can download the latest version at <http://nodejs.org/#download>.
4935
You can use one of these tools for version management (i.e., switching
5036
between Node.js versions):
5137

@@ -55,13 +41,13 @@ between Node.js versions):
5541

5642
- [nvm](https://github.com/creationix/nvm) (<https://github.com/creationix/nvm>)
5743

58-
As usual, you could copy example code at
59-
https://github.com/azat-co/fullstack-javascript/tree/master/code/06-hello, or
44+
As usual, you could copy the example code at
45+
https://github.com/azat-co/fullstack-javascript/tree/master/code/06-hello, TK or
6046
write your own program from scratch. If you wish to do the latter,
6147
create a folder `hello` for your "Hello World" Node.js application. Then
62-
create file a `server.js` and line by line type the code below.
48+
create a file `server.js` and line by line type the code below.
6349

64-
This will load the core `http` module for the server (more on the
50+
This line will load the core `http` module for the server (more on the
6551
modules later):
6652

6753
const http = require('http')
@@ -98,21 +84,20 @@ the following command:
9884

9985
$ node server.js
10086

101-
Open [localhost:1337](http://localhost:1337/) or
102-
[127.0.0.1:1337](http://127.0.0.1:1337/) or any other address you see in
103-
the terminal as a result of `console.log()` function, and you should see
87+
Open <http://localhost:1337> or <http://127.0.0.1:1337> or any other address you see in
88+
the terminal as a result of the `console.log()` function, and you should see
10489
"Hello World" in a browser. To shut down the server, press Control + C.
10590

106-
Note: The name of the main file could be different from server.js (e.g.,
107-
index.js or app.js). In case you need to launch the `app.js` file, just
91+
**Note** The name of the main file could be different from `server.js` (e.g.,
92+
`index.js` or `app.js`). In case you need to launch the `app.js` file, just
10893
use `$ node app.js`.
10994

11095
Node.js Core Modules
11196
====================
11297

11398
Unlike other programming technologies, Node.js doesn't come with a heavy
114-
standard library. The core modules of node.js are a bare minimum and the
115-
rest can be cherry-picked via the Node Package Manager (npm) registry.
99+
standard library. The core modules of Node.js are a bare minimum and the
100+
rest can be cherry-picked via the npm Node package manager registry.
116101
The main core modules, classes, methods, and events include:
117102

118103
- [http](http://nodejs.org/api/http.html)
@@ -124,7 +109,7 @@ The main core modules, classes, methods, and events include:
124109

125110
- [querystring](http://nodejs.org/api/querystring.html)
126111
(<https://nodejs.org/api/querystring.html>): Module for parsing query
127-
string from the URI
112+
strings from the URI
128113

129114
- [url](http://nodejs.org/api/url.html)
130115
(<https://nodejs.org/api/url.html>): Module for parsing URI
@@ -134,77 +119,61 @@ The main core modules, classes, methods, and events include:
134119
(<https://nodejs.org/api/fs.html>): Module for working with the file
135120
system
136121

137-
These are the most important core modules. Let's cover each of them.
122+
These are the most important core modules. Let's take a look at each of them.
138123

139124
### http
140125

141-
142-
This is the main module responsible for Node.js HTTP server. Here are
126+
This is the main module responsible for the Node.js HTTP server. Here are
143127
the main methods:
144128

145-
- `http.createServer()`: returns a new web server object
146-
147-
- `http.listen()`: begins accepting connections on the specified
129+
- `http.createServer()`: Returns a new web server object
130+
- `http.listen()`: Begins accepting connections on the specified
148131
port and hostname
149-
150-
- `http.createClient()`: node app can be a client and make requests
151-
to other servers
152-
153-
- `http.ServerRequest()`: incoming requests are passed to request
154-
handlers
155-
156-
- `data`: emitted when a piece of the message body is received
157-
158-
- `end`: emitted exactly once for each request
159-
160-
- `request.method()`: the request method as a string
161-
162-
- `request.url()`: request URL string
163-
164-
- `http.ServerResponse()`: this object is created internally by an
165-
HTTP server—not by the user, and used as an output of request
132+
- `http.createClient()`: Node app can be a client and make requests
133+
to other servers TK
134+
- `http.ServerRequest()`: Passes incoming requests to request
166135
handlers
136+
- `data`: Emitted when a piece of the message body is received
137+
- `end`: Emitted exactly once for each request
138+
- `request.method()`: The request method as a string
139+
- `request.url()`: Request URL string
167140

168-
- `response.writeHead()`: sends a response header to the request
169-
170-
- `response.write()`: sends a response body
141+
- `http.ServerResponse()`: Provides response/output of request handlers initiated by an
142+
HTTP server—not by the user
171143

172-
- `response.end()`: sends and ends a response body
144+
- `response.writeHead()`: Sends a response header to the request
145+
- `response.write()`: Sends a response body
146+
- `response.end()`: Sends and ends a response body
173147

174148
### util
175149

150+
This module provides a utility for debugging:
176151

177-
This module provides utilities for debugging. Some of the methods
178-
include:
179-
180-
- `util.inspect()`: Return a string representation of an object,
152+
- `util.inspect()`: Returns a string representation of an object,
181153
which is useful for debugging
182154

183155
### querystring
184156

185157
This module provides utilities for dealing with query strings. Some of
186158
the methods include:
187159

188-
- `querystring.stringify()`: Serialize an object to a query string
189-
190-
- `querystring.parse()`: Deserialize a query string to an object
160+
- `querystring.stringify()`: Serializes an object to a query string
161+
- `querystring.parse()`: Deserializes a query string to an object
191162

192163
### url
193164

194-
This module has utilities for URL resolution and parsing. Some of the
195-
methods include:
165+
This module has a utility for URL resolution and parsing:
196166

197-
- `parse()`: Take a URL string, and return an object
167+
- `url.parse()`: Takes a URL string, and returns an object which has URL information broken down into parts
198168

199169
### fs
200170

201-
fs handles file system operations such as reading and writing to/from
171+
`fs` handles file system operations such as reading and writing to/from
202172
files. There are synchronous and asynchronous methods in the library.
203173
Some of the methods include:
204174

205-
- `fs.readFile()`: reads file asynchronously
206-
207-
- `fs.writeFile()`: writes data to file asynchronously
175+
- `fs.readFile()`: Reads file asynchronously
176+
- `fs.writeFile()`: Writes data to file asynchronously
208177

209178
There is no need to install or download core modules. To include them in
210179
your application, all you need is to follow the syntax:
@@ -214,13 +183,9 @@ your application, all you need is to follow the syntax:
214183
The lists of non-core modules can be found at:
215184

216185
- [npmjs.org](https://npmjs.org): Node Package Manager registry
217-
218-
- Nipster (http://eirikb.github.io/nipster): npm search
219-
[Nipster](http://eirikb.github.com/nipster): npm search tool for
186+
- Nipster (<http://eirikb.github.io/nipster>): npm search tool for
220187
Node.js
221-
222-
- [node-modules(http://node-modules.com): npm search engine
223-
](node-modules(http://node-modules.com):%20npm%20search%20engine%20%20%20%20%20)
188+
- node-modules (<http://node-modules.com>): npm search engine
224189

225190
If you would like to know how to code your own modules, take a look at
226191
the article located here:
@@ -276,18 +241,32 @@ A typical `package.json` file might look like this:
276241

277242
While most of the properties in the `package.json` example above like
278243
`description` and `name` are self-explanatory, others deserve more
279-
explaining. Dependencies is an object, and each item has the name on the
280-
left side and the version number on the right side (e.g., "express":
281-
"&gt;= 2.5.6"). The version can be exact: for example, "express":
282-
"2.5.6," or greater than, or wild-card, for example, "express": "\*" (a
283-
great way to blow up your app in production with new untested
284-
dependencies: therefore not recommended).
244+
explaining. The `dependencies` property is an object, and each item has the name on the
245+
left side and the version number on the right side. For example, this statement tells npm to use Express version 2.5.6 or lower (earlier):
246+
247+
```js
248+
"express": "<= 2.5.6"
249+
```
250+
251+
The version can be exact (recommended). For example, this statement locks the version of Express at 2.5.6.:
252+
253+
```js
254+
"express": "2.5.6,"
255+
```
256+
257+
The versions can be specified to be greater-than (`>`), less-than (`<`), or any/wildcard (`*`). For example, this statement tell npm to use any version which usually means npm will get the latest stable version:
258+
259+
```js
260+
"express": "*"
261+
```
262+
263+
A wild card is a great way to blow up your app in production with new untested
264+
dependencies: therefore not recommended.
285265

286266
The `bin` property is for command-line utilities. It tells the system
287267
what file to launch. And the `scripts` object has scripts that you can
288-
launch with `$ ``npm` `run SCRIPT_NAME`. The `start` script and test are
289-
exceptions. You can run them with `$ ``npm`` start` and
290-
`$ ``npm`` test`.
268+
launch with `$ npm run SCRIPT_NAME`. The `start` and `test` scripts are
269+
exceptions. You can run them with `$ npm start` and `$ npm test`.
291270

292271
To update a package to its current latest version or the latest version
293272
that is allowable by the version specification defined in
@@ -300,14 +279,14 @@ Or for single module installation:
300279
$ npm install name-of-the-package
301280

302281
The only module used in this book's examples—and which does not belong
303-
to the core Node.js package—is `mongodb`. We'll install it later in the
304-
book.
282+
to the core Node.js package—is `mongodb`. We'll install it in the next chapter.
283+
284+
However, Heroku will need `package.json` to run npm on the server. The easiest way to create `package.json` is to execute:
305285

306-
Heroku will need `package.json` to run npm on the server.
286+
```
287+
$ npm init -y
288+
```
307289

308-
For more information on npm, take a look at the article "[Tour of
309-
npm](http://tobyho.com/2012/02/09/tour-of-npm/)"
310-
(http://tobyho.com/2012/02/09/tour-of-npm)
311290

312291
Deploying "Hello World" to PaaS
313292
===============================
@@ -318,26 +297,31 @@ your terminal:
318297

319298
$ git init
320299

321-
Git will create a hidden `.``git` folder. Now we can add files and make
300+
Git will create a hidden `.git` folder. Now we can add files and make
322301
the first commit:
323302

324303
$ git add .
325304
$ git commit -am "first commit"
326305

327-
Tip: To view hidden files on the macOS Finder app, execute this
306+
**Tip** To view hidden files on the macOS Finder app, execute this
328307
command in a terminal window:
329-
`defaults write ``com.apple.finder`` ``AppleShowAllFiles`` -``bool`` true`.
308+
309+
```
310+
defaults write com.apple.finder AppleShowAllFiles -bool true
311+
```
312+
330313
To change the flag back to hidden:
331-
`defaults write ``com.apple.finder`` ``AppleShowAllFiles`` -``bool`` false`.
314+
315+
```
316+
defaults write com.apple.finder AppleShowAllFiles -bool false
317+
```
332318

333319
Deploying to Microsoft Azure
334320
==========================
335321

336-
In order to deploy our "Hello World" application to Microsoft Azure, we
337-
must add Git **remote**. You could copy the URL from Microsoft Azure
338-
Portal, under Web Site, and use it with this command:
322+
In order to deploy our "Hello World" application to Microsoft Azure, we must add a Git remote destination that belongs to Azure. You could copy the URI/URL from the Microsoft Azure Portal, and use it with this command:
339323

340-
$ git remote add azure yourURL
324+
$ git remote add azure YOUR_AZURE_URI
341325

342326
Now we should be able to make a push with this command:
343327

@@ -352,15 +336,14 @@ To push changes, just execute:
352336
$ git commit -m "changing to hello azure"
353337
$ git push azure master
354338

355-
A more meticulous guide can be found in the tutorial
356-
https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac.
339+
A more meticulous guide can be found in the tutorial <https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-nodejs>. TK
357340

358341
Deploying to Heroku
359342
===================
360343

361344
For Heroku deployment, we need to create two extra files: `Procfile` and
362345
`package.json`. You could get the source code from
363-
https://github.com/azat-co/fullstack-javascript/tree/master/code/06-hello or
346+
<https://github.com/azat-co/fullstack-javascript/tree/master/code/06-hello> TK or
364347
write your own one.
365348

366349
The structure of the "Hello World" application looks like this:
@@ -370,9 +353,9 @@ The structure of the "Hello World" application looks like this:
370353
-Procfile
371354
-server.js
372355

373-
Procfile is a mechanism for declaring what commands are run by your
356+
`Procfile` is a mechanism for declaring what commands are run by your
374357
application’s dynos on the Heroku platform. Basically, it tells Heroku
375-
what processes to run. Procfile has only one line in this case:
358+
what processes to run. `Procfile` has only one line in this case:
376359

377360
web: node server.js
378361

@@ -391,7 +374,7 @@ For this example, we keep `package.json` simple:
391374
After we have all of the files in the project folder, we can use Git to
392375
deploy the application. The commands are pretty much the same as with
393376
Microsoft Azure except that we need to add Git remote, and create Cedar
394-
stack with:
377+
Stack with:
395378

396379
$ heroku create
397380

@@ -408,12 +391,8 @@ If everything went okay, you should see success logs in the terminal and
408391
Message Board with Node.js: Memory Store Version
409392
------------------------------------------------
410393

411-
Supplemental video which walks you through the implementation and
412-
demonstrates the project: http://bit.ly/1QnqO9P.
413-
414394
The first version of the Message Board back-end application will store
415-
messages only in runtime memory storage for the sake of KISS
416-
(http://en.wikipedia.org/wiki/KISS_principle). That means that each
395+
messages only in runtime memory storage for the sake of the KISS principle—keep it simple stupid (<http://azat.co/blog/kiss>). That means that each
417396
time we start/reset the server, the data will be lost.
418397

419398
We'll start with a simple test case first to illustrate the Test-Driven

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.