If the request, router, and controller stored in a single page, it's gonna be very inefficient for editing or finding the specific part of the code. So we separate the server <--> routers <--> controllers
.
Since NodeJS consider a file as an independent module, when we saprate the code, we have to export and import the files.
// file to export
const globalRouter = express.router();
export default globalRouter;
// file to import
import anyName from "../path/globalRouter";
export default KNOWS the file, so the name of the imported object doesn't have to be identical. However, this can only export ONE file.
// more than one objects to export
export const nameOne = (req, res) => {};
export const nameTwo = (req, res) => {};
export const nameThree = (req, res) => {};
export
in front of the variable can solve the problem.import {nameOne, nameTwo, nameThree} from "../path/nameController";
exported variables should be in the curly brackets, and the name have to be EXACT SAME.