2

I've read a lot of articles and post about the correct structure of angular and express. I just want to know, should I use the same node_modules folder to angular/express, or should I separete them ?

My structure is somthing like this:

  • application

    -- here I have the front end(angular)

  • server

    -- here I have the server files(express)

  • node_modules(should I put it here, or inside each folder?)

3
  • so did you find a solution to sharing the code between angular and express apps? Commented Jul 8, 2018 at 4:44
  • After read a lot of post, I opted for not share the package.json and separate each one of them. Commented Jul 11, 2018 at 4:36
  • You can serve angular as static files, however it creates a headache when trying to debug it on my IDE. I am opting to bundle my express app and angular app into a single folder on build but during development keep them separate.... however I am worried this will create future headaches when I want to automate my deploy on something like github or gitlab with a single button... I will have to do more build arrangement stuff. Commented Mar 2, 2019 at 17:37

1 Answer 1

1

The client and server should be separate projects with the separate package.json files and separate node_modules. Take a look at the client and server projects here: https://github.com/Farata/angulartypescript/tree/master/code-samples/Angular8/chapter13/ng-auction

Check the scripts section in the package.json in the client dir. If you run the command npm run build in the client dir, the angular app will be deployed on the server.

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

5 Comments

so there is no way to share code between client and server? There are a bunch of examples I can think of - validation, common libraries like geo, weather etc. Do you suggest I just do a lot of copy-paste? Is this what Node people do?
I keep the code that's needed on both client and server in separate modules (files) in a shared dir. The scripts from both client and server directories can import from the shared files.
I was studying this and seems like if you have package.json and node_modules in that shared folder it all doesn't work together as expected, does it? And debugging?
the shared folder doesn't have its own package.json - just the code to be shared between the client and server.
where does it import from then? Is it js or typescript? TS checks all imports and wouldn't compile if the corresponding package is not present

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.