@@ -146,193 +146,131 @@ Generating SSH keys and uploading them to SaaS/PaaS web sites will be covered la |
146 | 146 | Local HTTP Servers |
147 | 147 | ================== |
148 | 148 |
|
149 | | -Although you can do most of the front-end development without a local |
150 | | -HTTP server, it is needed for loading files with HTTP Requests/AJAX |
151 | | -calls. Also, it's just good practice in general to use a local HTTP |
152 | | -server. This way, your development environment is as close to the |
153 | | -production environment as possible. |
| 149 | +Although you can do most of the front-end development without a local HTTP server, it is needed for loading files with HTTP Requests/AJAX calls. Also, it's just good practice in general to use a local HTTP server. This way, your development environment is as close to the production environment as possible. |
154 | 150 |
|
155 | | -I recommend you use Node-based tools as static web servers. They lack |
156 | | -GUIs, but they are simple and fast. You can install them with npm (comes |
157 | | -with Node.js; instructions are later in this chapter): |
| 151 | +I recommend you use Node-based tools as static web servers. They lack GUIs, but they are simple and fast. You can install them with npm (comes with Node.js; instructions are later in this chapter): |
158 | 152 |
|
159 | 153 | - [*node-static*](https://github.com/cloudhead/node-static) (<https://github.com/cloudhead/node-static>): Static file server with built-in caching. Run `npm i -g node-static` to install. |
160 | 154 |
|
161 | 155 | - [*http-server*](https://www.npmjs.com/package/http-server) (<https://www.npmjs.com/package/http-server>): Zero-configuration command-line HTTP server. Run `npm i -g htt-server` to install. |
162 | 156 |
|
163 | 157 | If you prefer something with GUIs to a command-line interface (CLI), you might want to consider the following modifications of the Apache web server. MAMP, MAMP Stack, and XAMPP have intuitive GUIs that allow you to change configurations and host file settings. |
164 | 158 |
|
165 | | -- [*MAMP*](<http://www.mamp.info/en/index.html>) (<http://www.mamp.info/en/index.html>): Mac, Apache, MySQL, |
166 | | - PHP personal web server for macOS. |
167 | | -- [*MAMP Stack*](http://bitnami.com/stack/mamp) |
168 | | - (<http://bitnami.com/stack/mamp>): Mac app with PHP, Apache, MySQL, |
169 | | - and phpMyAdmin stack build by BitNami (Apple App Store) |
170 | | - (<https://itunes.apple.com/es/app/mamp-stack/id571310406?l=en>). |
171 | | - |
172 | | -- [*XAMPP*](http://www.apachefriends.org/en/xampp.html) |
173 | | - (<http://www.apachefriends.org/en/xampp.html>): Apache distribution |
174 | | - containing MySQL, PHP and Perl for Windows, Mac, Linux, and Solaris. |
| 159 | +- [*XAMPP*](http://www.apachefriends.org) (<http://www.apachefriends.org>): Apache distribution containing MySQL, PHP and Perl for Windows, macOS, Linux, and Solaris. |
| 160 | +- [*MAMP*](<http://www.mamp.info>) (<http://www.mamp.info>): Apache, MySQL, and PHP personal web server for macOS. |
| 161 | +- [*MAMP Stack*](https://bitnami.com/stack/mamp) (<https://bitnami.com/stack/mamp>): Another Apache, MySQL, and PHP stack for macOS. |
175 | 162 |
|
176 | 163 | Database: MongoDB |
177 | 164 | ----------------- |
178 | 165 |
|
179 | | -The following steps are better suited for macOS/Linux-based systems, |
180 | | -but with some modification they can be used for Windows systems as well |
181 | | -(i.e., $PATH variable, Step 3). Here we describe the MongoDB |
182 | | -installation from the official package, because we found that this |
183 | | -approach is more robust and leads to less conflicts. However, there are |
184 | | -many other ways to install it on Mac (<http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x>), for |
185 | | -example using Brew, as well as on other systems (<http://docs.mongodb.org/manual/installation>). |
186 | | - |
187 | | -1. MongoDB can be download ed at (<http://www.mongodb.org/downloads>). |
188 | | - For the latest Apple laptops, like MacBook Air, select OS X |
189 | | - 64-bit version. The owners of older Macs shouldbrowse the link at |
190 | | - (<http://dl.mongodb.org/dl/osx/i386>). |
| 166 | +The following steps are better suited for macOS/Linux-based systems, but with some modification they can be used for Windows systems as well (i.e., `$PATH` variable, Step 3). Here I describe the MongoDB installation from the official package, because I found that this approach is more robust and leads to less conflicts. However, there are many other ways to install it on macOS (<http://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x>), for example using Brew, as well as on other systems (<http://docs.mongodb.com/manual/installation>). |
191 | 167 |
|
192 | | - Tip To figure out the architecture type of your processor, type the $ uname -p at the command line. |
| 168 | +1. Download MongoDB from <http://www.mongodb.com/download-center#community>. For the latest Apple laptops, like MacBook, select macOS X 64-bit version. The owners of older Macs should browse the link at <http://dl.mongodb.com/dl/osx/i386>. |
193 | 169 |
|
194 | | -2. Unpack the package into your web development folder |
195 | | - (~/Documents/Development or any other). If you want, you could |
196 | | - install MongoDB into the /usr/local/mongodb folder. |
| 170 | + **Tip** To figure out the architecture type of your processor, type the $ uname -p at the command line. |
197 | 171 |
|
198 | | -3. Optional: If you would like to access MongoDB commands from anywhere |
199 | | - on your system, you need to add your mongodb path to the |
200 | | - $PATH variable. For macOS the open system *paths* file with: |
| 172 | +2. Unpack the package into your web development folder (`~/Documents/Development` or any other). If you want, you could install MongoDB into the `/usr/local/mongodb` folder. |
| 173 | +3. Optional: If you would like to access MongoDB commands from anywhere on your system, you need to add your `mongodb` path to the `$PATH` variable. For macOS, open system `/etc/paths` file with: |
201 | 174 |
|
202 | 175 | `sudo vi /etc/paths` |
203 | 176 |
|
204 | | - or, if you prefer TextMate: |
| 177 | + or, if you prefer VS Code: |
205 | 178 |
|
206 | | - `mate /etc/paths` |
| 179 | + `code /etc/paths` |
207 | 180 |
|
208 | 181 | And add this line to the /etc/paths file: |
209 | 182 |
|
210 | 183 | `/usr/local/mongodb/bin` |
211 | 184 |
|
212 | | -4. Create a data folder; by default, MongoDB uses /data/db. Please note |
213 | | - that this might be different in new versions of MongoDB. To create |
214 | | - it, type and execute the following commands in the terminal (Figure |
215 | | - 2-11): |
| 185 | +4. Create a `data` folder; by default, MongoDB uses `/data/db`. Please note that this might be different in new versions of MongoDB. To create it, type and execute the following commands in the terminal: |
216 | 186 |
|
217 | 187 | `$ sudo mkdir -p /data/db` |
218 | 188 | `$ sudo chown id -u /data/db` |
219 | 189 |
|
220 | | - If you prefer to use a path other than /data/db you could specify it |
221 | | - using the --dbpath option to mongod (the main MongoDB service). |
| 190 | + If you prefer to use a path other than `/data/db` you could specify it using the `--dbpath` option to `mongod` (the main MongoDB service). |
222 | 191 |
|
223 | | -5. Go to the folder where you unpacked MongoDB. That location should |
224 | | - have a bin folder in it. From there, type the following command in |
225 | | - your terminal: |
| 192 | +5. Go to the folder where you unpacked MongoDB. That location should have a bin folder in it. From there, type the following command in your terminal: |
226 | 193 |
|
227 | 194 | `$ ./bin/mongod` |
228 | 195 |
|
229 | | -6. If you see something like the following (and as in Figure 2-9) it |
230 | | - means that the MongoDB database server is running: |
| 196 | +6. If you see something like the following (and as in Figure 2-3) it means that the MongoDB database server is running: |
231 | 197 |
|
232 | 198 | `MongoDB starting: pid =7218 port=27017...` |
233 | 199 |
|
234 | | - By default, it's listening at <http://localhost:27017>. If you go to |
235 | | - your browser and type <http://localhost:28017> you should be able to see |
236 | | - the version number, logs, and other useful information. In this case the |
237 | | - MondoDB server is using two different ports (27017 and 28017): One is |
238 | | - primary (native) for the communications with apps and the other is a |
239 | | - web-based GUI for monitoring and statistics. In our Node.js code we'll |
240 | | - be using only 27017. Don't forget to restart the Terminal window after |
241 | | - adding a new path to the $PATH variable. |
| 200 | + By default, it's listening at <http://localhost:27017>. If you go to your browser and type <http://localhost:28017> you should be able to see the version number, logs, and other useful information. In this case the MondoDB server is using two different ports (27017 and 28017): One is primary (native) for the communications with apps and the other is a web-based GUI for monitoring and statistics. In our Node.js code we'll be using only 27017. Don't forget to restart the Terminal window after adding a new path to the `$PATH` variable. |
242 | 201 |
|
243 | 202 |  |
244 | 203 |
|
245 | | - ***Figure 2-9.** Starting up the MongoDB server* |
| 204 | + ***Figure 2-3.** Starting up the MongoDB server* |
246 | 205 |
|
247 | | - |
248 | | - Now, to take it even further, we can test to determine if we have access |
249 | | - to the MongoDB console/shell, which will act as a client to this server. |
250 | | - This means that we'll have to keep the terminal window with the server |
251 | | - open and running. |
| 206 | + Now, to take it even further, we can test to determine if we have access to the MongoDB console/shell, which will act as a client to this server. This means that we'll have to keep the terminal window with the server open and running. |
252 | 207 |
|
253 | 208 | 7. Open another terminal window at the same folder and execute: |
254 | 209 |
|
255 | 210 | `$ ./bin/mongo` |
256 | 211 |
|
257 | | - You should be able to see something like "MongoDB shell version 2.0.6 |
258 | | - ..." |
| 212 | + You should see something like "MongoDB shell version..." |
259 | 213 |
|
260 | 214 | 8. Then type and execute: |
261 | 215 |
|
262 | 216 | `> db.test.save( { a: 1 } )` |
263 | 217 | `> db.test.find()` |
264 | 218 |
|
265 | 219 | If you see that your record is being saved, then everything went well |
266 | | - (Figure 2-10). |
| 220 | + (Figure 2-4). |
267 | 221 |
|
268 | 222 |
|
269 | 223 |  |
270 | 224 |
|
271 | | -***Figure 2-10.** Running MongoDB client and storing sample data* |
| 225 | +***Figure 2-4.** Running MongoDB client and storing sample data* |
272 | 226 |
|
273 | 227 | Commands `find` and `save` do exactly what you might think they do. |
274 | 228 |
|
275 | | -Detailed instructions are also available at MongoDB.org: Install MongoDB |
276 | | -on OS X |
277 | | -(<http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x>). For |
278 | | -Windows users there is a good walk-through article at Installing MongoDB |
279 | | -(<http://www.tuanleaded.com/blog/2011/10/installing-mongodb>). |
| 229 | +The official MongoDB website has the detailed instructions for installing MongoDB on macOS at: <http://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x>. TK |
280 | 230 |
|
281 | | - Note MAMP and XAMPP applications come with MySQL—an open source traditional SQL database—and phpMyAdmin—a web interface for MySQL database. |
| 231 | +**Note** MAMP and XAMPP applications come with MySQL—an open source traditional SQL database—and phpMyAdmin—a web interface for MySQL database. |
282 | 232 |
|
283 | | -On macOS (and most UNIX systems), to close the process use Control + |
284 | | -C. If you use Control + Z it will put the process to sleep (or detach |
285 | | -the terminal window); in this case, you might end up with the lock on |
286 | | -data files and will have to use the kill command or Activity Monitor, |
287 | | -and manually delete the locked file in the data folder. In vanilla Mac |
| 233 | +On macOS (and most UNIX systems), to close the process use Control + C. If you use Control + Z it will put the process to sleep (or detach the terminal window); in this case, you might end up with the lock on data files and will have to use the `kill` command or Activity Monitor, and manually delete the locked file in the data folder. In vanilla Mac |
288 | 234 | Terminal Command + . is an alternative to Control + C. |
289 | 235 |
|
290 | | -Other Components |
| 236 | +Required Components |
291 | 237 | ---------------- |
292 | 238 |
|
293 | | -These are required technologies. Please make sure you have them before |
| 239 | +The following are required technologies. Please make sure you have them before |
294 | 240 | proceeding to the next chapter. |
295 | 241 |
|
296 | | -1. *Node.js:* We need it for build tools and back-end apps. Get version which has LTS even if the number is lower because LTS is the version which will be supported longer. <https://nodejs.org> |
297 | | -2. *Browser JS libraries:* We need them for front-end apps. |
298 | | -3. *LESS app:* We need it to compile LESS into CSS (macOS only). |
299 | | -4. *Compass*: A desktop client GUI app for working with MongoDB as a replacement of the Mongo shell/REPL. <https://www.mongodb.com/products/compass> |
| 242 | +1. *Node.js*: We need it for build tools and back-end apps. Get the version that has LTS even if the number is lower than the current NON-LTS version, because the LTS versions have longer support period: <https://nodejs.org>. |
| 243 | +2. *npm*: The Node package manager that comes bundled with Node (no need to install anything extra). |
| 244 | +3. *Browser JS libraries*: We need them for front-end apps. |
| 245 | + |
| 246 | +I highly recommend installing other optional but useful components: |
| 247 | + |
| 248 | +1. *nvm*: The Node version manager, which allows to switch between Node versions quickly. |
| 249 | +2. *Compass*: A desktop client GUI app for working with MongoDB as a replacement of the Mongo shell/REPL. <https://www.mongodb.com/products/compass> |
300 | 250 |
|
301 | 251 | ### Node.js Installation |
302 | 252 |
|
303 | | -Node.js is available at <http://nodejs.org/#download> (Figure 2-14). The |
304 | | -installation is trivial: Download the archive and run the \*.pkg package |
305 | | -installer. To check the installation of Node.js, you could type and |
306 | | -execute: |
| 253 | +Node.js is available at <http://nodejs.org/#download> (Figure 2-5). The installation is trivial: Download the archive and run the `*.pkg` package installer. To check the installation of Node.js, you could type and execute: |
307 | 254 |
|
308 | 255 | `$ node -v` |
309 | 256 |
|
310 | | -I use v8.11.1 for this book and tested all examples with v8.11.1. If you |
311 | | -use another version, do so at your own risk. I cannot guarantee that the |
312 | | -examples will run. |
313 | | - |
314 | | -Assuming you have 8.11.1, it should show something similar to this: |
| 257 | +I use v8.11.1 for this book and tested all examples with v8.11.1. If you use another version, do so at your own risk. I cannot guarantee that the examples will run. |
315 | 258 |
|
316 | | -`v8.11.1` |
| 259 | +Assuming you have 8.11.1, it should show something similar to this: `v8.11.1`. |
317 | 260 |
|
318 | | -If you want to switch between multiple versions of Node.js, there are |
319 | | -solutions for that: |
| 261 | +If you want to switch between multiple versions of Node.js, there are solutions for that: |
320 | 262 |
|
321 | 263 | - [*nvm*](https://github.com/creationix/nvm) (https://github.com/creationix/nvm ): Node.js Version Manager |
322 | | - |
323 | 264 | - [*Nave*](https://github.com/isaacs/nave) |
324 | 265 | (https://github.com/isaacs/nave): Virtual environments for Node.js |
325 | | - |
326 | 266 | - [*n*](https://github.com/tj/n) ( <https://github.com/tj/n> ): Node.js |
327 | 267 | version management |
328 | 268 |
|
329 | | -The Node.js package already includes [Node Package |
330 | | -Manager](https://npmjs.org) (https://npmjs.org) (NPM). We'll use NPM |
331 | | -extensively to install Node.js modules—Figure 2-11. |
| 269 | +The Node.js package already includes npm—[Node Package Manager](https://npmjs.org) (<https://npmjs.org>). We'll use npm extensively to install Node.js modules. |
332 | 270 |
|
333 | 271 |  |
334 | 272 |
|
335 | | -***Figure 2-11**. Node.js home page* |
| 273 | +***Figure 2-5**. Node.js home page that shows LTS and non-LTS versions* |
336 | 274 |
|
337 | 275 | ### Browser JavaScript Libraries |
338 | 276 |
|
|