Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Building API Routes in Express Building the Question Routes

Andrew Young
Andrew Young
Courses Plus Student 639 Points

Combine route script file into main script

I want to combine the API route and main script file into one file (I now this is not a good way). if I'm combining them how to do it? should I copy the whole file and define as a function and also do I still need to export?

1 Answer

Tom Geraghty
Tom Geraghty
24,174 Points

Why? But since you asked...

In your routes.js file, delete the line that has module.exports = ... then copy and paste the remaining code into your main (root folder) app.js file just below the import statements at the top.

Then remove all of the duplicate and (now) unnecessary imports at the top of app.js (including the import of Routes since you just put Routes into the main app.js file).

But again, why?