Saturday, 22 April 2017

ExpressJS: require multiple files with app.use()?

Routing:

app.use('/cms/', require('./routes/index.js'));
app.use('/cms/schools/', required('./routes/schools.js'));

Routes:

/cms/
/cms/schools/
/cms/schools/:schoolId/classes/:classId

Goal: I'd like to split ./routes/schools.js into two files: schools.js and schools_classes.js, to keep a better overview.

Problem: I'd like to keep the prefixed path /cms/schools/, but don't know how to split it correctly.

How can I structure the files to reach the desired goal? Thanks in advance!



via Mr. B.

No comments:

Post a Comment