1

Currently my test app is configured this way.

WebAPI is responsible for

  1. taking requests from client app
  2. communicating with MongoDB
  3. sending back responses.

And it use Node.js as web server and express 4 as back-end routing framework.

ClientApp is a front-end app based on Angular2 and uses another Node.js instance to serve as web server without Express 4. It does not use Express because there is no need. All the client-side routing is done by Angular2.

So I have two "backends" Node.js servers, one for WebAPI and the other for ClientApp.

The above works fine. My questions are that

  1. Is it common to combined the two apps (the WebAPI and ClientApp) under one Node.js server?

  2. If yes, would the Express routing URI and Angular2 router URI get confused with each other?

  3. If yes what are the advantages and disadvantages?

  4. If yes, then what are the common folder structure look like?

    proj-root

      |--routes folder (for express)
      |--views folder (for express, actually there is no view for WebAPI)
      |--models folder (for WebAPI with mongoose)
      |--services folder (for WebAPI)
      |--app folder (for Anglar2 components)
          |-- views folder (for Angular2 html views)
      |--node_modules folder (for both)
      |--index.html (Angular2 start point)
      |--server.js  (Express 4 startup file)
      |--package.json (for both)
      |--blabla
    

Does the above look OK?

1 Answer 1

1

Although there is no definite standard when it comes to project layout, it's recommended in express to leave the front end code inside /public folder. The node_modules folder for angular can be left inside /public folder too.

The routing can get a bit complicated, you'll need to forward all the Angular specific routes to /index or whatever your Angular entry point is and let Angular handle them. Other routes will be dealt with in express as usual.

In this way you can run Angular inside express without any problems and it's a cleaner way to layout and organise the project.

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

1 Comment

That make sense. Thanks.

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.