#expressjs with angular

10 messages · Page 1 of 1 (latest)

spark siren
#

Currently I'm pairing my expressjs APIs in a separate js file called index.js in the angular src directory. And running the same under 4050 port. Recently I noticed that my angular project already contain a file named 'server.ts' in project root directory with express package imported by default.

What is the purpose of this file? and can I deploy my expressjs APIs in this file so that I can invoke the same without running in a different port?

hearty urchin
#

The server.ts is for Angular SSR.
You can use it for API routes, but before Angular 19 server.ts is not used during development.

spark siren
#

So which way is recommended, maintaining the APIs in seprate expressjs API file and hosting the same, or using server.ts?

hearty urchin
#

If the API is really just for Angular, I would host them on the same express server. You just need some extra work arounds for development before Angular 19 comes out.

#

And from the way you worded your question, it seems like you're not actually using SSR (even though you configured Angular to do it).
So you might want to consider if you actually want it or not, which also influences the question.

spark siren
#

ok

#

I'm hosting the APIs sepretely as some of them needed to be extended in future

#

Here I'm separated components and services in two different directories in src. How to import auth service in login component? I'm unable to import using / or ./ or ../

hearty urchin
#

Your IDE should autocomplete the import.
But it should be ../../services/auth/auth.service.ts I think