How to use dependency of dependency in node.js

Viewed 19

Situation: I have a node.js library that uses sequelize to define and export models. In my backend app I use this library. This backend app also needs to access to stuff exported by sequelize.

Question: What is the correct way of accessing sequelize from my backend app?

  • I can add sequelize into my backend app's dependencies in package.json, but then if versions don't match some weird things start to happen. This is also hard to maintain, as I have many backend apps and I always have to manually keep track of versions.
  • I can access it via import sequelize from "boxlock-common-server/node_modules/sequelize";
  • ?

What is the correct way of doing this?

1 Answers

You can try using package aliases

"dependencies": {
   "pkg1": "npm:sequelize@6.23.0",
   "pkg2": "npm:sequelize@6.22.0"
}
Related