Search code examples
node.jsangularlibrariespackage.json

share code between angular and nodejs projects


I have some classes which were initially written for my Angular front-end, which I would also like to use in the NodeJS backend.

Those classes are written in typescript, while my NodeJS backend is written in javascript.

What would be the most straightforward way to share this code between both projects, so that both can use the same source code in the future?

It would be a bonus of course, if I could keep the code in typescript and private. But my fear is, that I will have to rewrite it to javascript and create a public npm package for them.


Solution

  • You might want to take a look at Nx. It allows you to create libraries which can be shared between a frontend app (e.g. Angular) and a backend Node.js app.