Folder structure for both server side and thick client web app

前端 未结 3 1932
一个人的身影
一个人的身影 2021-02-05 17:41

Currently I am using Node.js for the backend and either extjs or backbone for the client and I am now completely confused on the folder structure.

Using express

相关标签:
3条回答
  • 2021-02-05 18:04

    Heres my suggested folder structure:

    appname
      |--webapp
      |  |--img
      |  |--js
      |  |  |--controllers
      |  |  |  |--controller.js
      |  |  |--something.js
      |  |--css
      |  |--views
      |  |  |-- appview.ejs
      |  |--index
      |  |--404 etc.
      |--app.js
      |--package.json
      |--README
      |-- etc.
    

    I think its very tidy and easy to navigate in, because all the server and node_modules stuff is outside and the files I need for the application is in the "webapp" folder. If you really need a folder called "public" (I cant remember if express needs one or not) I think you can just rename the "webapp" folder to "public", or drop the "webapp" folder inside "public". I would also recommend using AngularJS instead of .ejs, but do what you want to do. :)

    0 讨论(0)
  • 2021-02-05 18:13

    Just put the whole /webapp under /public so you'll end creating, for instance, frontend's models under /public/webapp/models

    appname
      |--models
      |  |--appmodel.js
      |--public
      |  |  |--webapp // extjs/backbone files
      |  |  |  |--models
      |  |  |  |--controllers
      |  |  |  |--css
      |  |  |  |--js
      |  |  |  |--img
      |  |  |  |--views
      |  |  |  |  |--appview.ejs
      |  |  |  |  |--extbasedview.ejs
      |--routes
      |  |--router.js
      |--app.js
    
    0 讨论(0)
  • 2021-02-05 18:21

    In your place, I would do that way:

    appname
      |--ServerCode
      |  |--controllers
      |  |--models
      |  |  |--appmodel.js
      |  |--routes
      |  |  |--router.js
      |  |--views
      |  |  |--appview.ejs
      |  |--app.js
      |--public
      |  |--css
      |  |--js // any client-side javascripts
      |  |--models
      |  |--controllers
      |  |--...
    

    The main idea is to place public folder outside of the scope of your server javascript files.

    See an example here: https://github.com/madhums/node-express-mongoose-demo/

    0 讨论(0)
提交回复
热议问题