Each file you create is a module. module is an object. It has property called exports : {}
which is empty object by default.
you can create functions/middlewares and add to this empty exports object such as exports.findById() => { ... }
then require
anywhere in your app and use...
controllers/user.js
exports.findById = () => {
// do something
}
require in routes.js to use:
const {findyId} = './controllers/user'