Skip to content

Best practice to pass db and logger to routes #4733

Answered by dougwilson
paultman asked this question in Q&A
Discussion options

You must be logged in to vote

To really be able to answer your question, it would be import to state what the expected lifecycle of those objects are. Different lifecycles would have different constraints to where you can place them for access in your routes.

As for best practices, I think the Node.js ecosystem still has not determined what these are, and as a web framework, this is where express itself is "unopionated" on: how you want to perform IoC/DI in your application.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@paultman
Comment options

@dougwilson
Comment options

@paultman
Comment options

Answer selected by paultman
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants