Book Image

Web Development with MongoDB and Node - Third Edition

Book Image

Web Development with MongoDB and Node - Third Edition

Overview of this book

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.
Table of Contents (19 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Spy and stub everything!


When in doubt, the safest thing you can do when writing your tests is spy on everything and stub everything else. There are always going to be times when you'll want a function to execute naturally; in that case, leave it alone. Ultimately, you never want your tests to be dependent on any other system that includes database servers, other network servers, other APIs, and so on. You only want to test that your own code works, nothing more. If your code is expected to make a call to an API, spy on the actual call and just assert that your code attempted to make the call. Likewise, fake the response from the server via a stub and ensure that your code handles the response properly.

The easiest way to check for dependencies in your code is to stop any other services from running (your local node app, and so on), as well as possibly even disabling your network connection. If your tests time out or fail somewhere unexpectedly, it's likely because you missed a function you...