@@ -48,11 +48,11 @@ latest version at [nodejs.org/\#download](http://nodejs.org/#download). |
48 | 48 | You can use one of these tools for version management (i.e., switching |
49 | 49 | between Node.js versions): |
50 | 50 |
|
51 | | -- [n](https://github.com/tj/n) (https://github.com/tj/n) |
| 51 | +- [n](https://github.com/tj/n) (<https://github.com/tj/n>) |
52 | 52 |
|
53 | | -- [nave](https://github.com/isaacs/nave) (https://github.com/isaacs/nave) |
| 53 | +- [nave](https://github.com/isaacs/nave) (<https://github.com/isaacs/nave>) |
54 | 54 |
|
55 | | -- [nvm](https://github.com/creationix/nvm) (https://github.com/creationix/nvm) |
| 55 | +- [nvm](https://github.com/creationix/nvm) (<https://github.com/creationix/nvm>) |
56 | 56 |
|
57 | 57 | As usual, you could copy example code at |
58 | 58 | https://github.com/azat-co/fullstack-javascript/tree/master/07-hello, or |
@@ -114,23 +114,23 @@ standard library. The core modules of node.js are a bare minimum and the |
114 | 114 | rest can be cherry-picked via the Node Package Manager (NPM) registry. |
115 | 115 | The main core modules, classes, methods, and events include: |
116 | 116 |
|
117 | | -- [http](http://nodejs.org/api/http.html#http_http) |
118 | | - (https://nodejs.org/api/http.html\#http\_http): Module for working |
| 117 | +- [http](http://nodejs.org/api/http.html) |
| 118 | + (<https://nodejs.org/api/http.html>): Module for working |
119 | 119 | with HTTP protocol |
120 | 120 |
|
121 | 121 | - [util](http://nodejs.org/api/util.html) |
122 | | - (https://nodejs.org/api/util.html): Module with various helpers |
| 122 | + (<https://nodejs.org/api/util.html>): Module with various helpers |
123 | 123 |
|
124 | 124 | - [querystring](http://nodejs.org/api/querystring.html) |
125 | | - (https://nodejs.org/api/querystring.html): Module for parsing query |
| 125 | + (<https://nodejs.org/api/querystring.html>): Module for parsing query |
126 | 126 | string from the URI |
127 | 127 |
|
128 | 128 | - [url](http://nodejs.org/api/url.html) |
129 | | - (https://nodejs.org/api/url.html): Module for parsing URI |
| 129 | + (<https://nodejs.org/api/url.html>): Module for parsing URI |
130 | 130 | information |
131 | 131 |
|
132 | 132 | - [fs](http://nodejs.org/api/fs.html) |
133 | | - (https://nodejs.org/api/fs.html): Module for working with the file |
| 133 | + (<https://nodejs.org/api/fs.html>): Module for working with the file |
134 | 134 | system |
135 | 135 |
|
136 | 136 | These are the most important core modules. Let's cover each of them. |
@@ -141,52 +141,52 @@ These are the most important core modules. Let's cover each of them. |
141 | 141 | This is the main module responsible for Node.js HTTP server. Here are |
142 | 142 | the main methods: |
143 | 143 |
|
144 | | -- `http.createServer``()`: returns a new web server object |
| 144 | +- `http.createServer()`: returns a new web server object |
145 | 145 |
|
146 | | -- `http.listen``()`: begins accepting connections on the specified |
| 146 | +- `http.listen()`: begins accepting connections on the specified |
147 | 147 | port and hostname |
148 | 148 |
|
149 | | -- `http.createClient``()`: node app can be a client and make requests |
| 149 | +- `http.createClient()`: node app can be a client and make requests |
150 | 150 | to other servers |
151 | 151 |
|
152 | | -- `http.ServerRequest``()`: incoming requests are passed to request |
| 152 | +- `http.ServerRequest()`: incoming requests are passed to request |
153 | 153 | handlers |
154 | 154 |
|
155 | 155 | - `data`: emitted when a piece of the message body is received |
156 | 156 |
|
157 | 157 | - `end`: emitted exactly once for each request |
158 | 158 |
|
159 | | - - `request.method``()`: the request method as a string |
| 159 | + - `request.method()`: the request method as a string |
160 | 160 |
|
161 | 161 | - `request.url()`: request URL string |
162 | 162 |
|
163 | | -- `http.ServerResponse``()`: this object is created internally by an |
| 163 | +- `http.ServerResponse()`: this object is created internally by an |
164 | 164 | HTTP server—not by the user, and used as an output of request |
165 | 165 | handlers |
166 | 166 |
|
167 | | - - `response.writeHead``()`: sends a response header to the request |
| 167 | + - `response.writeHead()`: sends a response header to the request |
168 | 168 |
|
169 | | - - `response.write``()`: sends a response body |
| 169 | + - `response.write()`: sends a response body |
170 | 170 |
|
171 | | - - `response.end``()`: sends and ends a response body |
| 171 | + - `response.end()`: sends and ends a response body |
172 | 172 |
|
173 | 173 | ###util |
174 | 174 |
|
175 | 175 |
|
176 | 176 | This module provides utilities for debugging. Some of the methods |
177 | 177 | include: |
178 | 178 |
|
179 | | -- `util.inspect``()`: Return a string representation of an object, |
| 179 | +- `util.inspect()`: Return a string representation of an object, |
180 | 180 | which is useful for debugging |
181 | 181 |
|
182 | 182 | ###querystring |
183 | 183 |
|
184 | 184 | This module provides utilities for dealing with query strings. Some of |
185 | 185 | the methods include: |
186 | 186 |
|
187 | | -- `querystring.stringify``()`: Serialize an object to a query string |
| 187 | +- `querystring.stringify()`: Serialize an object to a query string |
188 | 188 |
|
189 | | -- `querystring.parse``()`: Deserialize a query string to an object |
| 189 | +- `querystring.parse()`: Deserialize a query string to an object |
190 | 190 |
|
191 | 191 | ###url |
192 | 192 |
|
@@ -201,9 +201,9 @@ fs handles file system operations such as reading and writing to/from |
201 | 201 | files. There are synchronous and asynchronous methods in the library. |
202 | 202 | Some of the methods include: |
203 | 203 |
|
204 | | -- `fs.readFile``()`: reads file asynchronously |
| 204 | +- `fs.readFile()`: reads file asynchronously |
205 | 205 |
|
206 | | -- `fs.writeFile``()`: writes data to file asynchronously |
| 206 | +- `fs.writeFile()`: writes data to file asynchronously |
207 | 207 |
|
208 | 208 | There is no need to install or download core modules. To include them in |
209 | 209 | your application, all you need is to follow the syntax: |
@@ -425,10 +425,10 @@ Unit Testing Node.js |
425 | 425 | We should have two methods: |
426 | 426 |
|
427 | 427 | 1. Get all of the messages as an array of JSON objects for the GET |
428 | | - `/message` endpoint using the `getMessages``()` method |
| 428 | + `/message` endpoint using the `getMessages()` method |
429 | 429 |
|
430 | 430 | 2. Add a new message with properties `name` and `message` for POST |
431 | | - `/messages` route via the `addMessage``()` function |
| 431 | + `/messages` route via the `addMessage()` function |
432 | 432 |
|
433 | 433 | We'll start by creating an empty `mb-server.js` file. After it's there, |
434 | 434 | let's switch to tests and create the `test.js` file with the following |
@@ -457,47 +457,47 @@ object with: |
457 | 457 |
|
458 | 458 | For testing our assumptions, we use core the Node.js module |
459 | 459 | [assert](http://nodejs.org/api/assert.html). It provides a bunch of |
460 | | -useful methods like `equal(``)`, `deepEqual``()`, etc. |
| 460 | +useful methods like `equal()`, `deepEqual()`, etc. |
461 | 461 |
|
462 | 462 | More advanced libraries include alternative interfaces with TDD and/or |
463 | 463 | BDD approaches: |
464 | 464 |
|
465 | 465 | - [Expect](https://github.com/LearnBoost/expect.js): Minimalistic |
466 | 466 | BDD-style assertion library:, for example, |
467 | | - `expect(user.name).``to.eql``('azat')` |
| 467 | + `expect(user.name).to.eql('azat')` |
468 | 468 |
|
469 | 469 | - [Should](https://github.com/shouldjs/should.js) |
470 | | - (https://github.com/shouldjs/should.js): BDD-style assertion library |
| 470 | + (<https://github.com/shouldjs/should.js>): BDD-style assertion library |
471 | 471 | that works by modifying `Object.prototype`: for example, |
472 | 472 | `user.name.should.be.eql``('azat')` |
473 | 473 |
|
474 | 474 | For more Test-Driven Development and cutting-edge automated testing, you |
475 | 475 | could use the following libraries and modules: |
476 | 476 |
|
477 | | -- [Mocha](https://mochajs.org) (https://mochajs.org/): Feature-rich |
| 477 | +- [Mocha](https://mochajs.org) (<https://mochajs.org>): Feature-rich |
478 | 478 | testing framework (my default choice) |
479 | 479 |
|
480 | 480 | - [NodeUnit](https://github.com/caolan/nodeunit) |
481 | | - (https://github.com/caolan/nodeunit): Simple assert-style unit |
| 481 | + (<https://github.com/caolan/nodeunit>): Simple assert-style unit |
482 | 482 | testing library |
483 | 483 |
|
484 | 484 | - [Jasmine](https://github.com/jasmine/jasmine) |
485 | | - (https://github.com/jasmine/jasmine): BDD testing framework with |
| 485 | + (<https://github.com/jasmine/jasmine>): BDD testing framework with |
486 | 486 | built-in assertion and spy (for mocking) libraries |
487 | 487 |
|
488 | | -- [Vows](http://vowsjs.org) (http://vowsjs.org/): BDD framework for |
| 488 | +- [Vows](http://vowsjs.org) (<http://vowsjs.org>): BDD framework for |
489 | 489 | Node.js tailored to testing asynchronous code |
490 | 490 |
|
491 | | -- [Chai](http://chaijs.com) (http://chaijs.com/): BDD/TDD assertion |
| 491 | +- [Chai](http://chaijs.com) (<http://chaijs.com>): BDD/TDD assertion |
492 | 492 | library that can be paired with a testing framework and has its own |
493 | 493 | versions of Should, Expect, and Assert |
494 | 494 |
|
495 | 495 | - [Tape](https://github.com/substack/tape) |
496 | | - (https://github.com/substack/tape): A minimalistic TAP (Test |
| 496 | + (<https://github.com/substack/tape>): A minimalistic TAP (Test |
497 | 497 | Anything Protocol) library |
498 | 498 |
|
499 | 499 | - [Jest](https://facebook.github.io/jest) |
500 | | - (http://facebook.github.io/jest/): Jasmine-and-Expect-like testing |
| 500 | + (<http://facebook.github.io/jest>): Jasmine-and-Expect-like testing |
501 | 501 | library with automatic mocks |
502 | 502 |
|
503 | 503 | You could copy the "Hello World" script into the `mb-server.js` file for |
@@ -509,7 +509,7 @@ We should see an error. Probably something like this one: |
509 | 509 |
|
510 | 510 | TypeError: Object #<Object> has no method 'getMessages' |
511 | 511 |
|
512 | | -That's totally fine, because we haven't written `getMessages``()` |
| 512 | +That's totally fine, because we haven't written `getMessages()` |
513 | 513 | method yet. So let's do it and make our application more useful by |
514 | 514 | adding two new methods: to get the list of the messages for Chat and to |
515 | 515 | add a new message to the collection. |
@@ -558,7 +558,7 @@ not to the main application code base. |
558 | 558 | Our server code will look slightly more interesting. For getting the |
559 | 559 | list of messages, according to REST methodology, we need to make a GET |
560 | 560 | request. For creating/adding a new message, it should be a POST request. |
561 | | -So in our createServer object, we should add `req.method``()` and |
| 561 | +So in our createServer object, we should add `req.method()` and |
562 | 562 | `req.url()` to check for an HTTP request type and a URL path. |
563 | 563 |
|
564 | 564 | Let's load the http module: |
@@ -579,7 +579,7 @@ To create a server and expose it to outside modules (i.e., `test.js`): |
579 | 579 | // Creates server |
580 | 580 |
|
581 | 581 | Inside of the request handler callback, we should check if the request |
582 | | -method is POST and the URL is `messages/``create.json`: |
| 582 | +method is POST and the URL is `messages/create.json`: |
583 | 583 |
|
584 | 584 | if (req.method == 'POST' && req.url == '/messages/create.json') { |
585 | 585 | // If method is POST and URL is messages/ add message to the array |
@@ -614,7 +614,7 @@ We output a message with a newly created object ID: |
614 | 614 | // Out put message, should add object id |
615 | 615 | }) |
616 | 616 |
|
617 | | -If the method is GET and the URL is `/messages/``list.json` output a |
| 617 | +If the method is GET and the URL is `/messages/list.json` output a |
618 | 618 | list of messages: |
619 | 619 |
|
620 | 620 | } else |
@@ -664,7 +664,7 @@ and this function returns an array of messages as a string/text: |
664 | 664 | return JSON.stringify(messages) |
665 | 665 | } |
666 | 666 |
|
667 | | -`addMessage``()` converts a string into a JavaScript object with the |
| 667 | +`addMessage()` converts a string into a JavaScript object with the |
668 | 668 | parse/deserializer method from querystring: |
669 | 669 |
|
670 | 670 | exports.addMessage = function (data){ |
@@ -770,46 +770,46 @@ Your application might grow bigger with more methods, URL paths to parse |
770 | 770 | and conditions. That is where frameworks come in handy. They provide |
771 | 771 | helpers to process requests and other nice things like static file |
772 | 772 | support, sessions, etc. In this example, we intentionally didn't use any |
773 | | -frameworks like Express (<http://expressjs.com/>) or Restify |
774 | | -(<http://mcavage.github.com/node-restify/>). Other notable Node.js |
| 773 | +frameworks like Express (<http://expressjs.com>) or Restify |
| 774 | +(<http://mcavage.github.com/node-restify>). Other notable Node.js |
775 | 775 | frameworks: |
776 | 776 |
|
777 | | -- [Derby](http://derbyjs.com/) (http://derbyjs.com/):MVC framework |
| 777 | +- [Derby](http://derbyjs.com) (<http://derbyjs.com>):MVC framework |
778 | 778 | making it easy to write real-time, collaborative applications that |
779 | 779 | run in both Node.js and browsers |
780 | 780 |
|
781 | 781 | - [Express.js](http://expressjs.com) |
782 | | - (http://expressjs.com/en/index.html): the most robust, tested and |
| 782 | + (<http://expressjs.com/en/index.html>): the most robust, tested and |
783 | 783 | used Node.js framework |
784 | 784 |
|
785 | | -- [Restify](http://mcavage.github.com/node-restify/) |
786 | | - (http://restify.com/): lightweight framework for REST API servers |
| 785 | +- [Restify](http://mcavage.github.com/node-restify) |
| 786 | + (<http://restify.com>): lightweight framework for REST API servers |
787 | 787 |
|
788 | | -- [Sails.js](http://sailsjs.org/) (http://sailsjs.org/): MVC Node.js |
| 788 | +- [Sails.js](http://sailsjs.org) (<http://sailsjs.org>): MVC Node.js |
789 | 789 | framework |
790 | 790 |
|
791 | | -- [hapi](http://spumko.github.io/) (http://spumko.github.io/): Node.js |
| 791 | +- [hapi](http://spumko.github.io) (<http://spumko.github.io>): Node.js |
792 | 792 | framework built on top of Express.js |
793 | 793 |
|
794 | | -- [Connect](http://www.senchalabs.org/connect/) |
795 | | - (https://github.com/senchalabs/connect\#readme): a middleware |
| 794 | +- [Connect](http://www.senchalabs.org/connect) |
| 795 | + (<https://github.com/senchalabs/connect#readme>): a middleware |
796 | 796 | framework for node, shipping with over 18 bundled middlewares and a |
797 | 797 | rich selection of third-party middleware |
798 | 798 |
|
799 | | -- [GeddyJS](http://geddyjs.org) (http://geddyjs.org/): a simple, |
| 799 | +- [GeddyJS](http://geddyjs.org) (<http://geddyjs.org>): a simple, |
800 | 800 | structured MVC web framework for Node |
801 | 801 |
|
802 | | -- [CompoundJS](http://compoundjs.com/) (http://compoundjs.com/) |
| 802 | +- [CompoundJS](http://compoundjs.com) (<http://compoundjs.com>) |
803 | 803 | (ex-RailswayJS): Node.JS MVC framework based on ExpressJS |
804 | 804 |
|
805 | | -- [Tower.js](http://towerjs.org) (http://tower.github.io/): a full |
| 805 | +- [Tower.js](http://towerjs.org) (<http://tower.github.io>): a full |
806 | 806 | stack web framework for Node.js and the browser |
807 | 807 |
|
808 | | -- [Meteor](http://meteor.com) (https://www.meteor.com/): open-source |
| 808 | +- [Meteor](http://meteor.com) (<https://www.meteor.com>): open-source |
809 | 809 | platform for building top-quality web apps in a fraction of the time |
810 | 810 |
|
811 | 811 | For a list of hand-picked frameworks, take a look at |
812 | | -(http://nodeframeworks.com). Ways to improve the application: |
| 812 | +(<http://nodeframeworks.com>). Ways to improve the application: |
813 | 813 |
|
814 | 814 | - Improve existing test cases by adding object comparison instead of a |
815 | 815 | string one |
|