Transcription of Node.js Notes for Professionals - GoalKicker.com
1 For for Programming BooksDisclaimerThis is an uno cial free book created for educational purposes and isnot a liated with o cial group(s) or company(s).All trademarks and registered trademarks arethe property of their respective owners300+ pagesof professional hints and tricksContentsAbout 1 .. Chapter 1: Getting started with 2 .. Section : Hello World HTTP server 4 .. Section : Hello World command line 5 .. Section : Hello World with Express 6 .. Section : Installing and Running 6 .. Section : Debugging Your NodeJS Application 7.
2 Section : Hello World basic routing 7 .. Section : Hello World in the REPL 8 .. Section : Deploying your application online 9 .. Section : Core modules 9 .. Section : TLS Socket: server and client 14 .. Section : How to get a basic HTTPS web server up and running! 16 .. Chapter 2: npm 19 .. Section : Installing packages 19 .. Section : Uninstalling packages 22 .. Section : Setting up a package configuration 23 .. Section : Running scripts 24 .. Section : Basic semantic versioning 24 .. Section : Publishing a package 25 .. Section : Removing extraneous packages 26.
3 Section : Listing currently installed packages 26 .. Section : Updating npm and packages 26 .. Section : Scopes and repositories 27 .. Section : Linking projects for faster debugging and development 27 .. Section : Locking modules to specific versions 28 .. Section : Setting up for globally installed packages 28 .. Chapter 3: Web Apps With Express 30 .. Section : Getting Started 30 .. Section : Basic routing 31 .. Section : Modular express application 32 .. Section : Using a Template Engine 33 .. Section : JSON API with ExpressJS 34.
4 Section : Serving static files 35 .. Section : Adding Middleware 36 .. Section : Error Handling 36 .. Section : Getting info from the request 37 .. Section : Error handling in Express 38 .. Section : Hook: How to execute code before any req and after any res 38 .. Section : Setting cookies with cookie-parser 39 .. Section : Custom middleware in Express 39 .. Section : Named routes in Django-style 39 .. Section : Hello World 40 .. Section : Using middleware and the next callback 40 .. Section : Error handling 42 .. Section : Handling POST Requests 43.
5 Chapter 4: Filesystem I/O 45 .. Section : Asynchronously Read from Files 45 .. Section : Listing Directory Contents with readdir or readdirSync 45 .. Section : Copying files by piping streams 46 .. Section : Reading from a file synchronously 47 .. Section : Check Permissions of a File or Directory 47 .. Section : Checking if a file or a directory exists 48 .. Section : Determining the line count of a text file 49 .. Section : Reading a file line by line 49 .. Section : Avoiding race conditions when creating or using an existing directory 49.
6 Section : Cloning a file using streams 50 .. Section : Writing to a file using writeFile or writeFileSync 51 .. Section : Changing contents of a text file 51 .. Section : Deleting a file using unlink or unlinkSync 52 .. Section : Reading a file into a Bu er using streams 52 .. Chapter 5: Exporting and Consuming Modules 53 .. Section : Creating a module 53 .. Section : Loading and using a module 54 .. Section : Folder as a module 55 .. Section : Every module injected only once 55 .. Section : Module loading from node_modules 56.
7 Section : Building your own modules 56 .. Section : Invalidating the module cache 57 .. Chapter 6: Exporting and Importing Module in 58 .. Section : Exporting with ES6 syntax 58 .. Section : Using a simple module in 58 .. Chapter 7: How modules are loaded 59 .. Section : Global Mode 59 .. Section : Loading modules 59 .. Chapter 8: Cluster Module 60 .. Section : Hello World 60 .. Section : Cluster Example 60 .. Chapter 9: Readline 62 .. Section : Line-by-line file reading 62 .. Section : Prompting user input via CLI 62 .. Chapter 10: 63.
8 Section : Exploring 63 .. Section : Scripts 66 .. Section : Basic project definition 67 .. Section : Dependencies 67 .. Section : Extended project definition 68 .. Chapter 11: Event Emitters 69 .. Section : Basics 69 .. Section : Get the names of the events that are subscribed to 69 .. Section : HTTP Analytics through an Event Emitter 70 .. Section : Get the number of listeners registered to listen for a specific event 70 .. Chapter 12: Autoreload on changes 72 .. Section : Autoreload on source code changes using nodemon 72.
9 Section : Browsersync 72 .. Chapter 13: Environment 74 .. Section : Accessing environment variables 74 .. Section : command line arguments 74 .. Section : Loading environment properties from a "property file" 75 .. Section : Using di erent Properties/Configuration for di erent environments like dev, qa, staging etc75 .. Chapter 14: Callback to Promise 77 .. Section : Promisifying a callback 77 .. Section : Manually promisifying a callback 77 .. Section : setTimeout promisified 78 .. Chapter 15: Executing files or commands with Child Processes 79.
10 Section : Spawning a new process to execute a command 79 .. Section : Spawning a shell to execute a command 79 .. Section : Spawning a process to run an executable 80 .. Chapter 16: Exception handling 82 .. Section : Handling Exception In 82 .. Section : Unhanded Exception Management 83 .. Section : Errors and Promises 84 .. Chapter 17: Keep a node application constantly running 86 .. Section : Use PM2 as a process manager 86 .. Section : Running and stopping a Forever daemon 87 .. Section : Continuous running with nohup 88.