Book Description

While there have been quite a few attempts to get JavaScript working as a server-side language, Node.js (frequently just called Node) has been the first environment that's gained any traction. It's now used by companies such as Netflix, Uber and Paypal to power their web apps. Node allows for blazingly fast performance; thanks to its event loop model, common tasks like network connection and database I/O can be executed very quickly indeed.

From a beginner's point of view, one of Node's obvious advantages is that it uses JavaScript, a ubiquitous language that many developers are comfortable with. If you can write JavaScript for the client-side, writing server-side applications with Node should not be too much of a stretch for you.

In this book, we'll offer a beginner's introduction to Node and its related technologies, and get you under way writing your first Node applications.

It contains:

  • What Is Node and When Should I Use It? by James Hibbard
  • A Beginner Splurge in Node.js by Camilo Reyes and Michiel Mulders
  • A Beginner's Guide to npm- the Node Package Manager by Michael Wanyoike and Peter Dierx
  • Forms, File Uploads and Security with Node.js and Express by Mark Brown
  • MEAN Stack: Build an App with Angular 2+ and the Angular CLI by Manjunath M
  • Debugging JavaScript with the Node Debugger by Camilo Reyes
  • Using MySQL with Node.js and the mysql JavaScript Client by Jay Raj
  • How to Use SSL/TLS with Node.js by Florian Rappl and Almir Bijedic

This book is for anyone who wants to start learning server-side development with Node.js. Familiarity with JavaScript is assumed, but we don't assume any previous back-end development experience.

Table of Contents

  1. Your First Week With Node.js
  2. Notice of Rights
  3. Notice of Liability
  4. Trademark Notice
  5. About SitePoint
  6. Preface
    1. Who Should Read This Book?
    2. Conventions Used
      1. Code Samples
      2. Tips, Notes, and Warnings
  7. Chapter 1: What Is Node and When Should I Use It?
    1. by James Hibbard
      1. Node or Node.js?
    2. What Is Node.js?
      1. Node Is Built on Google Chrome’s V8 JavaScript Engine
    3. How Do I Install Node.js?
      1. Node Binaries vs Version Manager
      2. "Hello, World!" the Node.js Way
      3. Node.js Has Excellent ES6 Support
    4. Introducing npm, the JavaScript Package Manager
      1. Installing a Package Globally
      2. Installing a Package Locally
      3. Working With the package.json File
    5. What Is Node.js Used For?
    6. Node.js Lets Us Run JavaScript on the Server
      1. The Node.js Execution model
      2. Are There Any Downsides?
      3. "Hello, World!" — Server Version
    7. What Kind of Apps Is Node.js Suited To?
    8. What Are the Advantages of Node.js?
    9. Other Uses of Node
    10. Conclusion
  8. Chapter 2: A Beginner Splurge in Node.js
    1. by Camilo Reyes & Michiel Mulders
    2. Why Node.js?
    3. Callbacks
    4. Asynchronous Operations
    5. File I/O
    6. A Web Server
    7. Async Await
    8. Conclusion
  9. Chapter 3: A Beginner’s Guide to npm — the Node Package Manager
    1. by Michael Wanyoike & Peter Dierx
    2. Installing Node.js
      1. Using a Version manager for Installation
    3. Node Packaged Modules
    4. Changing the Location of Global Packages
    5. Installing Packages in Global Mode
    6. Listing Global Packages
    7. Installing Packages in Local Mode
      1. A Quicker Way
      2. A Lockfile?
    8. Managing Dependencies with package.json
    9. Uninstalling Local Packages
    10. Installing a Specific Version of a Package
    11. Updating a Package
      1. Underscore has to be listed as a dependency in package.json
    12. Searching for Packages
    13. Re-installing Project Dependencies
    14. Managing the Cache
    15. Aliases
    16. Version Managers
    17. Conclusion
  10. Chapter 4: Forms, File Uploads and Security with Node.js and Express
    1. by Mark Brown
    2. Setup
    3. Displaying the Form
    4. Form Submission
    5. Validation and Sanitization
      1. Validation
      2. Sanitization
    6. The Valid Form
    7. Security considerations
      1. TLS over HTTPS
      2. Wear Your Helmet
      3. Cross-site Request Forgery (CSRF)
      4. Cross-site Scripting (XSS)
    8. File Uploads
      1. Populating File Inputs
    9. Thanks For Reading
  11. Chapter 5: MEAN Stack: Build an App with Angular 2+ and the Angular CLI
    1. by Manjunath M
    2. Introduction to the MEAN Stack
    3. Overview
    4. Prerequisites
    5. Creating the Backend Using Express.js and MongoDB
      1. Initializing npm
      2. Filling in app.js
      3. Setting up mongoose
      4. Working on the controller and the model
        1. Mongoose Assigns _id Fields by Default
    6. Building the Front End Using Angular
    7. Creating Components, a Model, and a Service
      1. View-List Component
      2. Add-List Component
    8. Finishing Touches
    9. Wrapping It Up
  12. Chapter 6: Debugging JavaScript with the Node Debugger
    1. by Camilo Reyes
    2. The Node CLI Debugger
      1. Don't Mind the Entry Point
      2. Time for a Demo of Ducks
    3. Client-Side Debugging
      1. A List of Ducks
      2. How Is This Debuggable Through Node?
    4. Debugging inside an Editor
    5. Debugging Transpiled JavaScript
    6. Conclusion
  13. Chapter 7: Using MySQL with Node.js and the mysql JavaScript Client
    1. by Jay Raj
    2. Quick Start: How to Use MySQL in Node
    3. Installing the mysql Module
    4. Getting Started
    5. Connecting to the Database
      1. Using Grunt to Watch the Files for Changes
    6. Executing Queries
      1. Reading
      2. Creating
      3. Updating
      4. Destroying
    7. Advanced Use
      1. Stored Procedures
      2. Escaping User Input
    8. Why Not Just USE an ORM?
    9. Conclusion
  14. Chapter 8: How to Use SSL/TLS with Node.js
    1. by Florian Rappl & Almir Bijedic
    2. HTTPS Everywhere
    3. Basic Communication
    4. HTTPS
    5. Generating Certificates
      1. Certbot
        1. Webroot
    6. Tighetning It Up
      1. HSTS
      2. Diffie–Hellman Strong(er) Parameters
    7. Conclusion