Lesson 11. Configurations and error handling

 

In lesson 10, you added Embedded JavaScript (EJS) to your application views. In this lesson, you add finishing touches to your application by modifying your package.json file to use a start script. This script changes the way that you start your application from terminal. Then you add error handling middleware functions to log errors and respond with error pages.

This lesson covers

  • Changing your application start script
  • Serving static pages with Express.js
  • Creating middleware functions for error handling
Consider this

You’re in full swing developing your recipe application. As is common in programming, you run into many errors, but you have no clear indication of those errors in your browser.

In this lesson, you explore ways to serve error pages to your browser window when appropriate.

11.1. Modifying your start script

To start this lesson, you modify a file that you haven’t touched in a while. The package .json file is created every time you initialize a new Node.js application, but you’ve changed hardly any of its values manually. In lesson 4, I talked about using the npm start command to start your application when that script is configured in your project’s package.json.

11.2. Handling errors with Express.js

11.3. Serving static files

Summary