Web Development with MongoDB and Node - Third Edition

Book description

Use the two popular web development stacks, Node.js and MongoDB, to build full-featured web applications

About This Book

  • Learn the new ECMAScript along with Node 8 and MongoDB to make your application more effective.
  • Get the up-to-date information required to launch your first application prototype using the latest versions of Node.js and MongoDB.
  • A practical guide with clear instructions to designing and developing a complete web application from start to finish using trending frameworks such as angular4 and hapi

Who This Book Is For

The book is designed for JavaScript developers of any skill level who want to get up-and-running using Node.js and MongoDB to build full-featured web applications. A basic understanding of JavaScript and HTML is the only prerequisite for this book.

What You Will Learn

  • Work with Node.js building blocks
  • Write and configure a web server using Node.js powered by the Express.js framework
  • Build dynamic HTML pages using the Handlebars template engine
  • Persist application data using MongoDB and Mongoose ODM
  • Test your code using automated testing tools such as the Mocha framework
  • Automate test cases using Gulp
  • Reduce your web development time by integrating third-party tools for web interaction.
  • Deploy a development environment to the cloud using services such as Heroku, Amazon Web Services, and Microsoft Azure
  • Explore single-page application frameworks to take your web applications to the next level

In Detail

Node.js builds fast, scalable network applications while MongoDB is the perfect fit as a high-performance, open source NoSQL database solution. The combination of these two technologies offers high performance and scalability and helps in building fast, scalable network applications. Together they provide the power for manage any form of data as well as speed of delivery.

This book will help you to get these two technologies working together to build web applications quickly and easily, with effortless deployment to the cloud. You will also learn about angular 4, which consumes pure JSON APOIs from a hapi server.

The book begins by setting up your development environment, running you through the steps necessary to get the main application server up-and-running. Then you will see how to use Node.js to connect to a MongoDB database and perform data manipulations.

From here on, the book will take you through integration with third-party tools to interact with web apps. You will see how to use controllers and view models to generate reusable code that will reduce development time. Toward the end, the book supplies tests to properly execute your code and take your skills to the next level with the most popular frameworks for developing web applications.

By the end of the book, you will have a running web application developed with MongoDB, Node.js, and some of the most powerful and popular frameworks.

Style and approach

A practical guide with clear instructions to designing and developing a complete web application from start to finish

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Welcome to JavaScript in the Full Stack
    1. A short introduction to Node.js
      1. The advantage that the V8 engine brings in
      2. Node.js is single-threaded!
      3. Non-blocking asynchronous execution
    2. npm - the Node Package Manager
    3. Sharing and reusing JavaScript
      1. Not just for building web servers!
      2. Real-time web application with Socket.io
      3. Networking and file IO
      4. Microservices
        1. Internet of things (IoT)
    4. A simple server with Node.js
      1. When to use Node.js
    5. The NoSQL movement
    6. A short introduction to MongoDB
      1. JSON-friendly database
      2. Schema-less design
      3. Various performance facets
    7. Node.js and MongoDB in the wild
    8. What to expect from this book
    9. Summary
  3. Getting Up and Running
    1. Installing Node.js
      1. Mac OS X
      2. Windows
      3. Linux
      4. Testing that Node.js is installed properly
      5. Online documentation
    2. Installing MongoDB
      1. Mac OS X installation instructions
      2. Windows 7/Windows 8 installation instructions
      3. Linux installation instructions
      4. Confirming successful MongoDB installation
      5. Bookmarking the online documentation
    3. Writing your first app
      1. Creating the sample application
      2. Getting the dependent modules in place
    4. Adding the application code
      1. Understanding the code
      2. Launching the sample app
      3. Checking the actual database
    5. Summary
  4. Node and MongoDB Basics
    1. A JavaScript primer
      1. Introducing es6
      2. Syntax basics
      3. Understanding the scope of variables
      4. Data types
      5. Operators and flows
      6. Understanding objects
      7. Understanding arrays
      8. Understanding functions
      9. Anonymous functions and callbacks
      10. JSON
    2. The basics of Node.js
      1. Node.js architecture
      2. Event-driven
      3. Asynchronous execution
      4. The module system
      5. The Node.js core
        1. HTTP
        2. Net
        3. Streams
    3. Installing modules using npm
    4. The basics of MongoDB
      1. The Mongo shell
      2. Inserting data
      3. Querying
      4. Updating data
      5. Deleting data
    5. Additional resources
    6. Summary
  5. Introducing Express
    1. Web application frameworks
    2. What is Express.js?
    3. Building a complete web application
      1. Designing the web application
      2. Organizing the files
      3. Creating the application's entry point
      4. Booting up the application
    4. Middlewares
      1. Creating custom middleware
      2. Order of middlewares
    5. The configure module
      1. Activating the configure module
    6. Routers and controllers
    7. Handlebars as View engines
    8. Summary
  6. Templating with Handlebars
    1. Templating engines
    2. Server-side and client-side templating
      1. Client-side templating
      2. Server-side templating
    3. The basics of Handlebars
      1. Binding an object to the template
      2. Embedding presentation logic
    4. Views
    5. Layouts
    6. Partial views
    7. Handlebars helpers
      1. Global helpers
      2. View-specific helpers
    8. Rendering the views
    9. Summary
  7. Controllers and View Models
    1. Controllers
    2. View models
    3. Updating the home controller
    4. Updating the image controller
      1. Displaying an image
      2. Uploading an image
    5. Helpers for reusable code
      1. The sidebar module
      2. The stats module
      3. The images module
      4. The comments module
      5. Testing the sidebar implementation
    6. Iterating on the UI
    7. Summary
  8. Persisting Data with MongoDB
    1. Using MongoDB with Node.js
      1. Connecting to MongoDB
      2. Inserting a document
      3. Retrieving a document
    2. Introducing Mongoose
      1. Schemas
      2. Models
      3. Built-in validation
      4. Static methods
      5. Virtual properties
        1. Context of method (this)
      6. Connecting with Mongoose
    3. Defining the schemas and models
      1. The models index file
    4. Adding CRUD to the controllers
      1. The home controller
      2. The image controller
        1. Index - retrieving an image model
        2. Create - inserting an image model
        3. Testing everything out so far
        4. The like button and updating an image model
        5. Comment - inserting a comment model
        6. Wrapping it up
      3. Helpers
        1. Introducing the async module
        2. The comments helper
        3. The sidebar helper
        4. Troubleshooting
        5. The stats helper
        6. The popular images helper
    5. Iterating by adding an image removal capability
      1. Adding a route
      2. Adding a controller handler
      3. Updating the Handlebars image page template
      4. Updating jQuery
    6. Refactoring and improvements
    7. Summary
  9. Creating a RESTful API
    1. What is an API?
    2. What is a RESTful API?
    3. Introducing Postman REST Client
      1. Installation instructions
      2. A quick tour of Postman REST Client
      3. Using the JSONView Chrome extension
    4. Creating a basic API server
      1. Creating sample JSON data
    5. Responding to GET requests
    6. Receiving data - POST and PUT requests
    7. Removing data - DELETE
    8. Consuming external APIs from Node.js
      1. Consuming an API endpoint using request
    9. Summary
  10. Testing Your Code
    1. The tools of the trade
      1. Running tests with the Mocha framework
      2. Asserting tests with Chai.js
      3. Getting started with Chai
      4. Spies and stubs with Sinon.js
      5. Stubbing node modules with Proxyquire
    2. Writing and running your first test
      1. Writing a test helper
    3. Testing the application
      1. Testing the routes
      2. Testing the server
      3. Testing a model
      4. Testing a controller
    4. Spy and stub everything!
    5. Automating everything
    6. Summary
  11. Deploying with Cloud-Based Services
    1. Cloud versus traditional hosting
      1. Infrastructure as a Service versus Platform as a Service
    2. An introduction to Git
    3. Deploying your application
      1. Nodejitsu
      2. Heroku
      3. Amazon Web Services
        1. Creating a MongoLab account and database
        2. Create and configure the AWS environment
      4. Microsoft Azure
      5. Digital Ocean
    4. Summary
  12. Popular Node.js Web Frameworks
    1. Koa
    2. Meteor
    3. Sails
    4. Flatiron
    5. total.js
    6. LoopBack
    7. Hapi
      1. Kick starting Hapi.js
        1. Scaffolding the Hapi app
        2. Setting up a server
        3. Creating APIs
        4. Creating a configuration-based architecture
    8. Summary
  13. Single Page Applications with Popular Frontend Frameworks
    1. Why use a frontend framework?
    2. What is a single page application?
      1. The TodoMVC project
      2. Backbone.js
      3. Ember.js
      4. React.js
      5. Angular
        1. Scaffolding the Angular app
        2. Understanding TypeScript and es6
        3. Modules and components
        4. Angular data flow architecture
        5. Services
        6. Forms
          1. Component communication
    3. Frontend development tools
      1. Automated build task managers
      2. Dependency management
      3. Modularity
      4. HTML template-rendering engines
      5. CSS transpiling
    4. Testing and test-driven development
      1. PhantomJS headless browser
    5. Summary

Product information

  • Title: Web Development with MongoDB and Node - Third Edition
  • Author(s): Bruno Joseph D'mello, Mithun Satheesh
  • Release date: September 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788395083