In this chapter, we pulled together Express-based API-serving code and webkit-built front-end code that you learned over the last two chapters to develop an end-to-end application. On top of that, we implemented authentication through Passport for three popular providers: Facebook, Twitter, and Google.
Running your Node.js project locally during development is often different than serving in production. You learned how to manage these differences with nconf configuration and the NODE_ENV environment variable.
We got deeper into Express, writing custom middleware for authentication and configuring persistent sessions. You also learned how to encapsulate stacks of middleware and routes into Express Routers—modular Express mini applications.
And as for code, you got more practice with async functions and Promises. These are crucial for writing readable, maintainable code that can handle both synchronous and asynchronous code flows in a consistent way.
At this point you’re ready to set off and start developing your own full-stack JavaScript applications on Node.js. I wish you the best of luck!
In the next and final chapter of the book, we’ll take a step away from the nitty-gritty of writing Node.js code by hand. Instead, you’ll learn how to use Node-RED, a visual tool for composing event flow–based Node.js programs. But before you go, check out these bonus tasks. See you soon!
As in all previous chapters, the configuration for accessing Elasticsearch in this chapter looks like this:
| | "es": { |
| | "host": "localhost", |
| | "port": 9200, |
| | "books_index": "books", |
| | "bundles_index": "b4" |
| | }, |
And constructing Elasticsearch URLs used template strings like this:
| | const url = `http://${es.host}:${es.port}/${es.bundles_index}/bundle`; |
But in this chapter you learned how to use the URL to construct URLs relative to other paths.
Your task is to change the configuration to look like this:
| | "es": { |
| | "books_index": "http://localhost:9200/books", |
| | "bundles_index": "http://localhost:9200/b4" |
| | }, |
Then, with your new knowledge of the URL class, refactor the existing Elasticsearch URL building code to use it.
Currently, webpack presses all of the CSS for the B4 app into the dist/bundle.js file. However, it typically makes sense to put the CSS in a separate distributable file from the bundled JavaScript.
Your task is to configure webpack to create a separate CSS file using the extract-text-webpack-plugin module. Start by installing it with npm.
| | $ npm install --save-dev -E extract-text-webpack-plugin@3.0.1 |
Check out the extract-text-webpack-plugin module page for instructions.[107]
https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://cloud.google.com/nodejs/getting-started/authenticate-users#authenticating_users