How does nodejs separate the interface to another JS file to write?

clipboard.png
index.jsabout:

clipboard.png
JS express
:localhost:3000/about:

clipboard.png

Mar.13,2021

//
app.use('/about',require('./test.js'));
 app.use('/run',require('./run.js'));
 .....
 
//test.js
//
router=express.Router();
router.get('/',function(){..})///about/
router.get('/one',function(){..})///about/one

text.js

export default function(req,res){
    res.send('about');
}

in the main file

app.get('/about',require('./test.js'));

1. How to introduce
2 without require. The router of express understands


encapsulates the route into the router.js as an object export
app.js introduces router and use


you have no idea what the landlord is talking about. What the landlord means is that he does not want to put the interface code in server.js and wants to extract a file to store the interface code separately.
the landlord can declare an interface file of interface.js on the outside, then export the contents in the server.js, require ('interface') in the server.js, and then pass the app as a parameter

.
Menu