Over the last couple of chapters, you’ve been building up the skills to create back-end APIs for a server using Express, and a front end using TypeScript and webpack. In this chapter, you’ll put it all together from end to end to create a full-stack JavaScript application in Node.js.
This is the capstone course of the B4 application arc. Recall that B4, the Better Book Bundle Builder, is a Node.js application that empowers users to create named reading lists called book bundles. It relies on Elasticsearch to store information about books and book bundles. Chapters 5 and 6 were about manipulating this data, getting everything in place to build APIs on top.
In Chapters 7 and 8, you learned to create RESTful APIs and a UI that communicates with them, respectively, but they were run as separate programs. In this chapter, we’ll pull them together along with authentication and session management. Users will be able to sign in with Facebook, Twitter, or Google, and then view and create book bundles.
By the end of this chapter, you’ll have the foundation you need to put together Node.js-based web applications yourself, from scratch.
It’s a long chapter, but even so, it doesn’t cover everything there is to know about deploying your Node.js application in production. The state of the art moves too quickly for that. But you should have enough that you can ask the right questions to take you the rest of the way.
We’ll cover these aspects of Node.js development in this chapter:
At this point, we’re pretty far removed from the Node.js core, but we’ll still touch on some important topics. You’ll use the URL class from the url module to construct application-specific URLs. You’ll use the NODE_ENV environment variable to control whether your application runs in development or production mode. And you’ll also use the built-in path module to perform OS-specific filesystem path manipulations.
We’ll hit on some patterns both new and old. You’ll get more practice writing Express middleware, and you’ll learn to encapsulate stacks of middleware and routes into Express Routers. You’ll also use Passport to authenticate users and store their session state with the express-session module.
In this chapter, you’ll get a lot more practice writing async functions—the important new way of handling both synchronous and asynchronous code flows in a consistent style. You’ll also make richer use of the fetch API for performing authenticated API requests.
It takes a surprising amount of supporting code to build this kind of app. You’ll learn how to create and use a localhost alias for development. You’ll install and use Social Bootstrap and Font Awesome, both of which provide well-designed UI components. Lastly, you’ll use Redis, a fast database and caching server for storing user sessions in production mode.
Users of the B4 application that you’ll be making will be able to sign in using any of three authentication services: Facebook, Twitter, or Google. I’ll walk you through how to set up all of them. First we’ll quickly get the initial project running locally, during which I’ll explain the few bits it contains that you haven’t seen yet. From there we’re ready to build on top. Let’s go!