Setting up the Express, CORS, and the Morgan Middleware

Learn how to set up the Express, CORS, and Morgan middleware.

Setting up the Express middleware

To set up the express.json() middleware, we take the following steps below:

Step 1: Install the express framework

To add express to the dependency object in our Node application, we run the command below at the root of the project:

npm install express

Step 2: Import and inject the express.json() middleware

To set up the express.json() middleware, we will need to require express in the server.js file as seen below:

const express = require('express')
const app = express()

With express imported, we can now inject the express.json() middleware:

app.use(express.json());

đź“ť Note: The express.json()is only available in Express v4.16.0 and above.

Get hands-on with 1300+ tech skills courses.