Dockering a nodejs application with external dependencies

Viewed 496

We are building Node.js microservices. For some reusable components we have created a utils folder. This folder is outside the actual microservices package. When we run the microservices, we can refer to that code using require(../../utils/logger) and it works like a charm. However when trying to create the docker image for my microservices

project the container gives me an error saying:
Error: Cannot find module '../../Utils/logger

which makes a lot of sense as we are building the docker image inside the microservice project. There are few architectural decisions which needs to be taken here:

  1. We move the utils code into each microservice as required.

    • Pro: Microservice remains self sustained completely and no code level dependency on any other package.
    • Cons: Maintenance of cross cutting concerns and the changes would be cumbersome.

2.Create a private npm module and inject dependency into the microservice package.json file. Not sure if that would work.

Any suggestions on this are highly appreciated.

Best, - Vaibhav

2 Answers
Related