Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Build a REST API With Express Completing and Testing the API Connecting the API and Database

Peter Kolawa
Peter Kolawa
36,765 Points

Which one: .param() or route method is more efficient? Andrew as always messed it up... ;/

To be honest: I hate Andrews tutorials. They are always messed up, too long and hard to stand until the end.

But despite that fact: is dealing with one .param() method for URL params more efficient than repeating ourselves in every single router endpoint method?

1 Answer

Jesus Mendoza
Jesus Mendoza
23,287 Points

Hey Peter,

In my opinion, it's the same when it comes to performance, but better when it comes to code readability.

Lets say you want to query the database everytime you enter a route with an expecific param. Performance wise you will make a call to the database everytime you hit the route with that expecific param, no matter if you declare it on the params route or the individual route.

But when it comes to code readability, you only write that code once (on the param route) instead of having to write it on every route with that expecific param.

That's just my opinion and I might be wrong!

Have a nice day