简体   繁体   中英

Node.JS Express structuring a big app

I am interested in creating a CRUD Rest API using Node.js together with express. I was wondering if their was a structuring standard of some sort or MVC framework which is used in the industry to structure my code create models etc...

I know that I should structure the different models into different npm projects but how to structure a single project is what I am looking for...

Also I am very interested in using a mediator design pattern to decrease coupling between the different modules.

Any examples/blogs/gits/books will help

Thanks

I did a screencast on this topic in which I propose an app structure that has served me well for APIs and projects with UIs. Do I claim this is gospel and then end-all-be-all? No. But it has served me well.

In short it looks something like this:

app_root
  app
    routes 
      - route handlers go here
    models 
      - if you use models
    commands 
      - if you use commands
    middleware 
      - middlewarez
  config
    application.js - the stuff that bootstraps your application.  Reusable in contexts other than your server (thing testing)
    routes.js - All your route mappings in one place
  test
    test_helper.js - Bootstrap your testing (require config/application.js, etc)
    models 
      - tests for your models (follow suit for other things under app)
  server.js - starts up your webserver

I put this empty app structure up on GitHub here .

You could use Google's AngularJS + Node.JS where the angular frameworkwork separates view and controller. Look into Angular site for example and tutorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM