Let's carry out this refactoring process in a new branch called create-user/refactor-modules:
$ git checkout -b create-user/refactor-modules
Then, create a directory at src/middlewares; this is where we will store all of our middleware modules. Inside it, create four files—one for each middleware function:
$ mkdir -p src/middlewares && cd src/middlewares$ touch check-empty-payload.js \ check-content-type-is-set.js \ check-content-type-is-json.js \ error-handler.js
Then, move the middleware functions from src/index.js into their corresponding file. For example, the checkEmptyPayload function should be moved to src/middlewares/check-empty-payload.js. Then, at the end of each module, export the function as the default ...