Unit 3. Connecting to a database

Unit 2 taught you how to set up a Node.js application with Express.js. By this point, you should feel comfortable building a basic web application with Express.js routing and templating. This unit is about taking the application you built in unit 2 and connecting it to a database. A database is where values can be stored permanently, as opposed to the data in earlier lessons, which was reset every time your application restarted.

In this book, you learn to use MongoDB, a popular database for Node.js. First, you download and install Mongo on your computer. Then you explore the MongoDB shell, a database environment similar to the Node.js REPL shell. Next, you learn some database theory behind structuring your database and the data within it. You see how models fit into the model-view-controller (MVC) architecture and how they interact with your application’s database via a package called Mongoose. Last, you explore how a database schema—an outline of your structured data—helps you relate data objects to one another.

With the goal of building a Node.js application that can store user information and display that information back on your screen, this unit covers the following topics:

  • Lesson 13 introduces MongoDB, a NoSQL database that stores data in a JSON structure. In this lesson, you learn how MongoDB works with Express.js and install the database program on your computer. You also create a database and insert some data by using the MongoDB shell.
  • Lesson 14 shows how to connect your MongoDB database to an Express.js application. After initial setup, you learn how object-oriented programming (OOP) can help you build reliable models for an MVC-structured Node.js application. For your models, you install and use the Mongoose package, an object-document mapper (ODM).
  • Lesson 15 discusses the types of query commands you can use with your MongoDB database from within the Node.js application. You also implement JavaScript promises to work with Mongoose to build a more streamlined, ES6-friendly application.
  • Finally, lesson 16 shows how to put your skills to the test by implementing a MongoDB database for the Confetti Cuisine cooking-school application. In this capstone exercise, you save user data and newsletter emails.

Get ready to collect and store data in lesson 13.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset