3

So, I guess this question has been asked and answered before, but it seems like most questions seem to be about sharing code between client and server when the client and server code reside in the same project.

I have server code in Node.js (TypeScript), model classes specifically, that I want to re-use on the client, but the client and server code is completely separated. What are my best options for re-using that code?

Possible solution:

  • Publish all model classes as an npm package and install that in the client project

Cons: Have to create a new package every time something changes, feels too complicated.

What other options do I have?

msk
  • 1,052
  • 3
  • 15
  • 31
  • You can use [npm link](https://docs.npmjs.com/cli/link) – Nitzan Tomer Mar 17 '17 at 16:53
  • Maybe [_path mapping_](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) can help? – Paleo Mar 17 '17 at 17:13
  • For proper modulization, putting into new package is the better way to go. You can then use `npm link` as suggested by Nitzan Tomer – unional Mar 17 '17 at 19:13

0 Answers0