{"id":15697405,"url":"https://github.com/madhusudhand/donode","last_synced_at":"2025-10-25T14:43:00.208Z","repository":{"id":57215130,"uuid":"76341452","full_name":"madhusudhand/donode","owner":"madhusudhand","description":"Super fast \u0026 Lightweight node framework to build RESTful APIs.","archived":false,"fork":false,"pushed_at":"2017-11-24T08:01:30.000Z","size":112,"stargazers_count":6,"open_issues_count":17,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T00:57:04.262Z","etag":null,"topics":["es6","framework","javascript","mvc","node-framework","node-js","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madhusudhand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-13T09:03:01.000Z","updated_at":"2022-12-12T05:06:36.000Z","dependencies_parsed_at":"2022-08-24T22:31:17.690Z","dependency_job_id":null,"html_url":"https://github.com/madhusudhand/donode","commit_stats":null,"previous_names":["donode/donode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madhusudhand%2Fdonode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madhusudhand%2Fdonode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madhusudhand%2Fdonode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madhusudhand%2Fdonode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madhusudhand","download_url":"https://codeload.github.com/madhusudhand/donode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171251,"owners_count":21865290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es6","framework","javascript","mvc","node-framework","node-js","nodejs"],"created_at":"2024-10-03T19:19:08.474Z","updated_at":"2025-10-25T14:43:00.157Z","avatar_url":"https://github.com/madhusudhand.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# donode\n\nSuperfast \u0026 Lightweight node framework for building RESTful APIs.\n\n**Simple** . **Flexible** . **High Performance** . **ES2015+**\n\nEnables developers to focus on writing reusable application logic in a\nhighly modular approach.\n\n**Use [donode-cli](https://www.npmjs.com/package/donode-cli), to get started.**\n\n**NOTE: Requires node 8.0 or higher **\n\n## High Performance\n\nHere are the [performance results](https://github.com/madhusudhand/node-performance).\n\n## Documentation\n\n### App Structure\n\nCreate the app using [donode-cli](https://www.npmjs.com/package/donode-cli),\nit is as **simple** and **modular** as\n\n- app\n  - controllers\n  - middleware\n  - headers.js\n  - routes.js\n- env\n  - development.env.js\n  - production.env.js\n- app.js\n\n### Routing\n\n**One Place** for all your routes and they go into **app/routes.js**.\n\nA Route can be as *simple* as\n\n```\n{\n  path: '/hello',\n  method: 'GET',\n  handler: 'HelloController@get'\n}\n```\n| Property | Type      |  Description  |\n| :---     | :---      |  :---         |\n| path     | string    |  url for the route |\n| method   | string    |  can be one of GET, POST, PUT, UPDATE, DELETE. |\n| handler  | string    |  **format**: *SomeController@method* \u003cbr\u003e Here in this format **SomeController** is the controller (a class) located in **app/controllers** directory. \u003cbr\u003e\u003cbr\u003e And **method** (name after @) is the name of the method in the given controller, which gets called and send response. \u003cbr\u003e\u003cbr\u003e more details available in **controllers** section.  |\n\n#### Advanced Routing\n\nA Route can take options like *middleware, headers, children*.\n\n```\n{\n  path: '/user/{id}',\n  method: 'GET',\n  handler: 'UserController@get',\n  middleware: ['Auth'],\n  headers: ['allow-cors'],\n  children: [{\n  \tpath: '/settings',\n    method: 'GET',\n    handler: 'UserController@settings',\n  }]\n}\n```\n| Property | Type      |  Description  |\n| :---     | :---      |  :---         |\n| path     | string    |  A route can have params in its path. \u003cbr/\u003e *syntax*: **{param}** \u003cbr\u003e\u003cbr\u003e *example*: \u003cbr\u003e*/user/{id}* can respond to */user/1, /user/123* etc..|\n| method   | string    |  values are not limited GET, POST, PUT, UPDATE, DELETE. \u003cbr/\u003e can be any type of request that server can listen to. (HEAD, OPTIONS etc..) |\n| handler  | string    |  A controller can be from a sub directory inside controllers directory. \u003cbr\u003e *syntax*: **subdirectory/SomeController@method** \u003cbr/\u003e here in this *SomeController* is located in *app/controllers/subdirectory*. |\n| middleware | array \u003cbr\u003e or \u003cbr\u003e object    |  A Middleware is an intermediate handler which can be used to perform some pre-checks such as Auth. \u003cbr\u003eIt is a class located in **app/middleware** directory and will be called before the **handler** method. \u003cbr\u003e\u003cbr\u003e ***Array** Syntax*: **['Middleware1', 'Middleware2']** \u003cbr\u003e\u003cbr\u003e A list of strings which are the names of the *classes* from *app/middleware* directory. When attached to a route, these will be called in the given order before the actual **handler**. \u003cbr\u003e\u003cbr\u003e more details available in **middleware** section. \u003cbr\u003e\u003cbr\u003e ***Object** syntax*: \u003cbr\u003e**{ \u003cbr\u003e \u0026nbsp;\u0026nbsp; all: ['Middleware1'],\u003cbr\u003e \u0026nbsp;\u0026nbsp; only: ['Middleware2'],\u003cbr\u003e \u0026nbsp;\u0026nbsp; children: ['Middleware3'] \u003cbr\u003e }** \u003cbr\u003e\u003cbr\u003e -- **all**: attached to current the route and all its children. \u003cbr\u003e -- **only**: attached only to current route. \u003cbr\u003e -- **children**: attached to all the children, but not to current route. \u003cbr\u003e\u003cbr\u003e **Note**: All are optional. Any of them can be given/ignored. \u003cbr\u003e\u003cbr\u003e **Order**: middleware defined under **all, children** which are coming from parent routes (if any), then **all, only** of current route. |\n| headers  | array    | **headers** property allows to attach a set of headers that can to be sent along with the *response* for every request. \u003cbr\u003e It takes an array of stings which are defined in **app/headers.js**. \u003cbr\u003e\u003cbr\u003e **syntax**\u003cbr\u003e ['allow-cors', 'json-content'] \u003cbr\u003e\u003cbr\u003e **Note**: currently headers attached to a route will apply only to it. Not to children. Object syntax is yet to come !!!|\n| children | array    |  Routes can be nested with this attribute. \u003cbr\u003e This takes list of sub-routes which takes same set of above properties. \u003cbr\u003e\u003cbr\u003e **example route config** \u003cbr\u003e{ \u003cbr\u003e \u0026nbsp;\u0026nbsp;path: '/user/{id}', \u003cbr\u003e\u0026nbsp;\u0026nbsp;method: 'GET',\u003cbr\u003e\u0026nbsp;\u0026nbsp;handler: 'UserController@get',\u003cbr\u003e\u0026nbsp;\u0026nbsp;children: [{\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; path: '/settings', \u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; method: 'POST', \u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; handler: 'UserController@settings'\u003cbr\u003e\u0026nbsp;\u0026nbsp;}]\u003cbr\u003e } \u003cbr\u003e\u003cbr\u003e this will register the routes\u003cbr\u003e **GET**: */user/{id}* \u003cbr\u003e **POST**: */user/{id}/settings* |\n\n\n\n### Controllers\n\n**app/controllers**: A place for all controllers of the app.\n\nA controller is a class which inherits **Controller** from donode, and has the handler methods of a route.\n\n```js\nconst Controller = require('donode').Controller;\n\nclass HomeController extends Controller {\n  constructor() {\n    super();\n  }\n\n  get(request, response) {\n    response.send({\n      'app': 'works !!!'\n    });\n  }\n}\n\nmodule.exports = HomeController;\n```\n\nThe method **get(request, response)** will be the handler for a route.\n\n```\nhandler: 'HomeController@get'\n```\n\nIt gets *request, response* as params.\n\n#### Request\n\nIt is a native *Node Request* object. Along with default properties it also contains\n\n\n| Property | Route     |  Values  |\n| :---     | :---      |  :---         |\n| query | /user?p1=123\u0026p2=donode | { p1: 123, p2: 'donode' } |\n| params | /user/{id} | { id: 123 } |\n| body | - | payload sent along with request |\n| headers | - | headers sent along with request |\n| url | - | {  } |\n| originalUrl | /user/{id} | /user/123 |\n| method | - | GET, POST, PUT, DELETE etc.. |\n\n\n#### Response\n\nIt is a native *Node Response* object. Along with default properties it also contains\n\n\n| Method | definition     |  Description  |\n| :---     | :---      |  :---         |\n| send | send([response_code,] responseObject) | It takes optional response code and a response object which whill be sent. \u003cbr\u003e\u003cbr\u003e default: 200 (OK) |\n| reject | reject([response_code], responseObject) | takes optional response_code and rejection responseObject. \u003cbr\u003e\u003cbr\u003edefault: 401 (bad request) |\n| setHeader | setHeader(type, value) | takes header type and value |\n\n\n### Middleware\n\n```\nconst Middleware = require('donode').Middleware;\n\nclass Auth extends Middleware {\n  constructor() {\n    super();\n  }\n\n  handle(request, response, next) {\n    // do some auth validation here\n\n    // if (not authorized)\n    // return response.send(401, { some: 'error data' });\n\n    // else (proceed to the controller hander)\n    return next();\n  }\n}\n\nmodule.exports = Auth;\n```\n\n**Note**:\n\nWhen response.send() or response.reject() are called in a middleware, the call chain stops and handler method will not be called.\n\n### Environments\n\nEnvironments for the app can be managed by creating corresponding configuration file\n\n\u003e env/\u003cenvironment-name\u003e.env.js\n\nThis configuration can be used with **NODE_ENV** while running the app.\n\n\u003e $ NODE_ENV=\u003cenvironment-name\u003e node app.js\n\n**Examples:**\n\n```\nNODE_ENV=production node app.js\nNODE_ENV=stage node app.js\n```\n\nWithout NODE_ENV it defaults to `development.env.js`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadhusudhand%2Fdonode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadhusudhand%2Fdonode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadhusudhand%2Fdonode/lists"}