This book guides you through setting up for MERN-based web development, to building real-world web applications of varying complexities.
Before diving into the development of these web applications, we are going to answer the following questions in this chapter to set the context for using MERN:
- What is the MERN stack?
- Why is MERN relevant today?
- When is MERN a good fit for developing web apps?
- How is this book organized to help master MERN?
MongoDB, Express, React, and Node are used in tandem to build web applications and make up the MERN stack. In this lineup, Node and Express bind the web backend together, MongoDB serves as the NoSQL database, and React makes the frontend that the user sees and interacts with.
Node has an event-driven architecture capable of asynchronous, non-blocking I/O. Its unique non-blocking I/O model eliminates the waiting approach to serving requests. This allows building scalable and lightweight real-time web applications that can efficiently handle many requests.
Node's default package management system, the Node package manager or npm, comes bundled with the Node installation. Npm gives access to hundreds of thousands of reusable Node packages built by developers all over the world and boasts that it is currently the largest ecosystem of open source libraries in the world.
In any web application developed with Node, Express can be used as a routing and middleware web framework that has minimal functionality of its ownâan Express application is essentially a series of middleware function calls.
Middleware functions are functions that have access to the HTTP request and response objects, and also the next middleware function in the web application's request-response cycle.
Find out what is possible with Express.js at expressjs.com.
MongoDB is a top choice when deciding on a NoSQL database for any application. It is a document-oriented database that stores data in flexible, JSON-like documents. This means fields can vary from document to document and data models can evolve over time in response to changing application requirements.
Applications that place a high priority on availability and scalability benefit from MongoDB's distributed architecture features. It comes with built-in support for high availability, horizontal scaling using sharding, and multi-data center scalability across geographic distributions.
MongoDB has an expressive query language, enabling ad hoc queries, indexing for fast lookups, and real-time aggregation that provides powerful ways to access and analyze data while maintaining performance even when data size grows exponentially.
Explore MongoDB features and services atÂ https://www.mongodb.com/.
Large applications that display a lot of changing data can be fast and responsive if built with React, as it takes care of efficiently updating and rendering just the right UI components when specific data changes. React does this efficient rendering with its notable implementation of a virtual DOM, setting React apart from other web UI libraries that handle page updates with expensive manipulations directly in the browser's DOM.
Check out resources on React atÂ https://reactjs.org/.
Consistency across the stack also makes it easy to learn and work with MERN, reducing the overhead of adopting a new stack and the time to develop a working product. Once the working base of a MERN application is set up and a workflow established, it takes less effort to replicate, further develop, and extend any application.
Organizations of all sizes have been adopting the technologies in this stack based on their needs because they can build applications faster, handle highly diverse requirements, and manage applications more efficiently at scale.
Developer communities surrounding the very popular MERN stack technologies are quite diverse and growing on a regular basis. With lots of people continuously using, fixing, updating, and willing to help grow these technologies, the support system will remain strong for the foreseeable future. These technologies will continue to be maintained, and resources are very likely to be available in terms of documentation, add-on libraries, and technical support.
The ease and benefits of using these technologies are already widely recognized. Because of the high-profile companies that continue adoption and adaptation, and the growing number of people contributing to the code bases, providing support, and creating resources, technologies in the MERN stack will continue to be relevant for a long time to come.
Given the unique features attributed to each technology, along with the ease of extending functionalities of this stack by integrating other technologies, the range of applications that can be built with this stack is actually quite diverse.
These days, web applications are, by default, expected to be rich client apps that are immersive, interactive, and don't fall short on performance and availability. The grouping of MERN strengths makes it perfect for developing web applications that meet these very aspects and demands.
Moreover, novel and upcoming attributes of some of these technologies, such as low-level operation manipulation with Node, large file streaming capabilities withÂ MongoDB GridFS, and virtual reality features on the web using React 360, make it possible to build even more complex and unique applications with MERN.
It may seem reasonable to pick specific features in the MERN technologies, and argue why these don't work for certain applications. But given the versatile nature of how a MERN stack can come together and be extended; these concerns can be addressed in MERN on a case-by-case basis. In this book,Â we will demonstrate how to make such considerations when faced with specific requirements and demands in the application being built.
To demonstrate the breadth of possibilities with MERN and how you can easily start building a web application with varying features, this book will showcase everyday use web applications alongside complex and rare web experiences:
The preceding screenshot gives a glimpse of the four different MERN applications developed in the rest of this bookÂ
For the first MERN application,Â we will build a basic social media application inspired by Twitter and Facebook. This social media platform will implement simple features such as post sharing, liking and commenting, following friends, and an aggregated news feed.
E-commerce web applications of all sorts are abundant on the internet, and these will not go out of style anytime soon. Using MERN, we will build an online marketplace application covering core aspects, such as support for seller accounts, product listings, a shopping cart for customers, and payment processing.
To test out some advanced MERN capabilities, a more immersive application, such as a media streaming application, is the next pick. Inspired by features from Netflix and YouTube, this application will implement content uploading and viewing capabilities with a media content upload feature for content providers, and real-time content streaming for viewers.
The release of React 360 makes it possible to apply web VR capabilities to React user interfaces. We will explore how to create rare web experiences with React 360 in MERNÂ by putting together a basic virtual reality game application for the web. Users will be able to make and play VR games, where each game will have animated VR objects that the player can collect to complete the game.
The book is organized into five parts, progressing from basic to advanced topics, taking you on a journey of building MERN from the ground up, then using it to develop different applications with simple to complex features, while demonstrating how to extend the capabilities of the MERN stack based on application requirements.
Chapter 1, Unleashing React Applications with MERNÂ and Chapter 2, Preparing the Development EnvironmentÂ set the context for developing web applications in a MERN stack and guide you through setting up your development environment.
Chapter 3,Â Building a Backend with MongoDB, Express, and NodeÂ andÂ Chapter 4,Â Adding a React Frontend to Complete MERNÂ show how to bring the MERN stack technologies together to form a skeleton web application with minimal and basic features. This skeletal MERN application acts as a base for the four main applications developed in the rest of the book.
In this part, you will become familiar with the core attributes of a MERN stack web application by building out two real-world applicationsâa simple social media platform in Chapter 5,Starting with a Simple Social Media Application, and an online marketplace in Chapter 6, Exercising New MERN Skills with an Online MarketplaceÂ and Chapter 7, Extending the Marketplace for Orders and Payments.
Chapter 8, Building a Media Streaming Application,Â Chapter 9, Customizing Media Player and Improve SEO, Chapter 10, Developing a Web-Based VR Game, andÂ Chapter 11, Making the VR Game Dynamic using MERNÂ show how this stack can be used to develop applications with more complex and immersive features, such as media streaming and virtual reality using React 360.
FinallyÂ Chapter 12, Following Best Practices and Developing MERN FurtherÂ wraps up the preceding chapters and applications developed by expanding on best practices to follow to make successful MERN applications, suggesting improvements and further developments.
You may choose to use the book out of the prescribed order based on your experience level and preference. A developer who is very new to MERN can follow the path set out in the book. For a more seasoned JS developer, the chapters in theÂ Building MERN from the ground upÂ -Â a skeleton applicationÂ section would be a good place to start setting up the base application, then pick any of the four applications to build and extend.
The content in this book is practical-oriented and covers the implementation steps, code, and concepts relevant to building out each MERN application. It is recommended that, rather than attempting to just read through the chapters, you should run the relevant code in parallel, and browse through the application features whileÂ following the explanations in the book.
Chapters that discuss code implementations will point to GitHub repositories containing the complete code with instructions on how to run the code. You can pull the code, install, and run it before reading through the chapter:
You may consider the recommended following steps outlined to follow theÂ implementations in this book:
- Before diving into the implementation details discussed in the chapter, pull code from the relevant GitHub repository
- Follow instructions with the code to install and run the application
- Browse the features of the running application, while reading the feature descriptions in the relevant chapter
- With the code running in development mode and also open in the editor, refer to the steps and explanations in the book to get a deeper understanding of the implementations
In this chapter, we discovered the context for developing web applications in the MERN stack, and how this book will help you develop with this stack.
MERN stack projects integrate MongoDB, Express, React, and Node to build web applications. Each of the technologies in this stack has made relevant strides in the world of web development. These are widely adopted and continue to improve with the support of growing communities. It is possible to develop MERN applications with diverse requirements, ranging from everyday use applications to more complex web experiences. The practical-oriented approach in this book can be used to grow MERN skills from basic to advanced, or for diving right into building the more complex applications.
In the next chapter, we will start gearing up for MERN application development by setting up the development environment.