share code between angular and nodejs projects

Viewed 1327

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.

2 Answers

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.

You can share some of the code between Angular and Node projects,for that you need to choose 'Nest' framework on the node side.

Benifits of Nest

  1. It uses typescript
  2. It follows the same syntax as Angular
  3. It follows modularity in the architecture

For detailed information, please follow official nest website

xplat - cross platform

This cross platform already has the solution to your problem.

xplat official website

Related