Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vuongtran/ef1a843cb84426d2e54e to your computer and use it in GitHub Desktop.
Save vuongtran/ef1a843cb84426d2e54e to your computer and use it in GitHub Desktop.
RESTful API sample structure using Node.js, Express.js included tesing
Let's lool at the following example structure for RESTful API using Node.js, Express.js included tesing
app/
|---models/
|---controller/
|---helpers/
|---middlewares/
|---tests/
|---models/
|---controllers/
|---middlewares/
|---node_modules/
|---app.js
|---package.json
models/ – represents data, implements business logic and handles storage
controllers/ – defines your app routes and their logic
helpers/ – code and functionality to be shared by different parts of the project
middlewares/ – Express middlewares which process the incoming requests before handling them down to the routes
tests/ – tests everything which is in the other folders
node_modules/ - all npm requried for app
app.js – initializes the app and glues everything together
package.json – remembers all packages that your app depends on and their versions
@nimatrazmjo
Copy link

Do you thing controllers is enough for routes and their logic for the large project. I mean if the project getting large the code will not be clean if we put all the logic and routes inside of controller ?

@Flexicon
Copy link

I would agree with nimatullah and say that on larger projects it's probably better to keep routing and handling/ passing of data to controllers and move our business logic to another abstraction, such as Services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment