AngryOliver
AngryOliver

Reputation: 397

How to re-use models between node.js projects?

I have two node.js (more specifically, express.js) projects. Lets consider "project A" which is the main project, and "project B" which is an "ad-hoc" (for a certain purpose) project. Project B needs project A models.

How to re-use project A's models wisely without repeating code? (And how is it working practically, in terms of how the two projects are arranged?)

Thanks.

Upvotes: 0

Views: 201

Answers (1)

Jani Hartikainen
Jani Hartikainen

Reputation: 43243

A decent approach to deal with this would be to separate it as a module you can install using npm. (You can install private packages with it)

This would allow you to easily manage any dependencies your library has. You can define them into the package.json file, and whenever a project needs the library, you simply install it and npm deals with the dependencies.

Upvotes: 3

Related Questions