Git Product home page Git Product logo

node-js-folder-structure's Introduction

Node JS Folder Structure

Some best practices in structuring a large node js project folder.

|app.js
|package.json
|--app
|   |--models
|        |--user.js
|        |--user-schema.js
|   |--views
|   |--controllers
|--config
|   |--authentication.js
|   |--credentials.js
|   |--routes
|        |--page_1.js
|        |--page_2.js
|        |--login.js
|        |--signup.js
|   |--database.js
|   `--locale
|        |--en_us.js
|--public
|   |--controllers
|--react
|   |--atoms
|        |--button.jsx
|        |--button.sass
|        |--button-responsive.sass
|   |--molecules
|   |--organisms
|   |--templates
|   |--pages
|--views
|   |--layouts
|   |--pages
|--tests
|   |--users
|   |--admins
  • Folder naming can be singular or plural, but should be standardized

Root folders:

  • app - holds the whole express code structure
  • public - holds the static file. Best if server using a CDN.
  • views - contains the static html views

App folder contains the following:

  • models - contains the schema for the models and database
  • routes - contains the express js routes
  • stores - database access layer code
  • configs - holds the whole app configuration, including routes endpoints, auth and database config
  • helpers - a.k.a. useful utils
  • middlewares - the heart of express

API folder will contain the following:

  • entity - the request params, including validation
  • graph - helper to parse the response
  • action - config for the services which contains the method, routes, and commands to be dispatcher
  • command - triggered by command to handle a specific requests
  • store - database access layer

Deciding factor for the app architecture

  • how reusable is it from the scale of 1 to 10?
  • how granular should the files be? preferable 150 loc (line of codes) per file
  • each file does only one thing best
  • reusable codes are extracted out

Client side folder structure

  • is separated from the server side
  • communicates with the server side through REST calls or websocket

###Folder Structure:

  • assets (including images, fonts, etc)
  • scripts (we do not choose js owing to the variety of compilers available now such as coffeescript, jsx, etc and thus do not want to be tied to a specific technology)
  • stylesheets (css, less, sass files resides here)
  • data (static data)

node-js-folder-structure's People

Contributors

alextanhongpin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.