0

What is the proper project structure when creating an Angular 6 application, and an API server that share type definitions?

Example:

On the client:

this.httpService.get<Hero[]>(apiUrl + '/heroes')

On the server:

app.get('/heroes', async (req, res) => {
  const heroes: Hero[] = await db.Heroes.findAll<Hero>()
  res.status(200).send(heroes)
}

I need to share the Hero definition between projects.

  • Do I build my server in a sub-directory of the angular app?
  • Do I build my server app first, then reference its source code somehow from the Angular app?
  • Do I build a third Models project, write all the definitions there, and somehow reference them?

1 Answer 1

1

You need to have a structure as follows,

enter image description here

where web is the front end and services is going to be your node/go services.

Do I build my server in a sub-directory of the angular app?

No , you can separate both.

Do I build my server app first, then reference its source code somehow from the Angular app?

Yes thats better so you do not have to worry about Model when you start with your angular app.

Do I build a third Models project, write all the definitions there, and somehow reference them?

Not necessary. You can have your models in your node project itself.

I need to share the Hero definition between projects. I would strongly suggest not to do that, becauase sometimes you are not binding all properties on the front end. Have a separate Interface for your front end models.

Sign up to request clarification or add additional context in comments.

2 Comments

Different models will be the exception.. How do I make a shared library for the majority?
You can use a share folder to use the shared ones

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.