{"id":22727279,"url":"https://github.com/noviel/osnova","last_synced_at":"2025-04-13T21:43:24.628Z","repository":{"id":57316582,"uuid":"61723010","full_name":"Noviel/osnova","owner":"Noviel","description":"Modular Node.js Server","archived":false,"fork":false,"pushed_at":"2020-03-20T07:39:25.000Z","size":6339,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T20:44:05.283Z","etag":null,"topics":[],"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/Noviel.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-06-22T13:53:09.000Z","updated_at":"2017-02-09T15:32:26.000Z","dependencies_parsed_at":"2022-09-18T20:51:19.156Z","dependency_job_id":null,"html_url":"https://github.com/Noviel/osnova","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fosnova","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fosnova/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fosnova/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fosnova/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Noviel","download_url":"https://codeload.github.com/Noviel/osnova/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788867,"owners_count":21161726,"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":[],"created_at":"2024-12-10T17:11:37.520Z","updated_at":"2025-04-13T21:43:24.602Z","avatar_url":"https://github.com/Noviel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OSNOVA\n\n## bI?\n\nModular Node.js server based on express and mongoose.\n\n## Install\n\nnpm: \n```sh\nnpm i osnova [--save] \n```\nor yarn:\n```sh\nyarn add osnova\n```   \n    \n## Usage\n```javascript\nconst OSNOVA = require('osnova');\nconst osnova = OSNOVA();\n\nosnova.start((osnova) =\u003e {\n  console.log(`Hello from OSNOVA v${osnova.getVersion()}`);\n});\n```\n    \n### Modules\n\nOSNOVA is modular by its nature. Modules are just functions, that will be called on start. \nEvery module added to OSNOVA will be called with `osnova` as an argument.\n\nThe very basic module:\n ```javascript\n const myCounter = ({ initialCount } = { initialCount: 0 }) =\u003e osnova =\u003e {\n   let count = initialCount;\n \n   osnova.next({ \n     counter: {\n       value() { return count; },\n       increment() { count++; },\n       decrement() { count--; }\n     }\n   })    \n }\n ```\n`osnova.next({ export })` assigns `export` object to `osnova`. So `myCounter` will be available \nas `osnova.counter` for other modules.\nImportant moment here - `next()` is not just making available some functionality from outside. \nIt is also an indicator that module has done his business and OSNOVA should execute next one in the queue.\nEvery module **MUST CALL** `osnova.next()` even if it is not exporting anything. \nBy this mechanism modules will guaranteed to be executed in an \norder they were added and any next module \ngain access to exports of all previous modules:\n\n```javascript\nconst osnova = OSNOVA({\n  modules: [ \n    myCounter({ initialCount: 100 }), \n    moduleWithoutOptions, \n    iCanCallPreviousModulesSafely\n  ]\n});\n```\n`osnova.start` takes the module as an argument. It will be added in queue as the last one.\nAnd then module queue will be executed. So module added by `start` can safely use any other module.\n\n```javascript\nosnova.start((osnova) =\u003e {\n  const counter = osnova.counter;\n  counter.increment();\n  console.log(`Hello from OSNOVA v${osnova.getVersion()}. Count = ${counter.value()}`);\n});\n```\n\n### Core modules\nThese modules are built-in and will be called by default in the next order:\n\n#### Mongo\nExports `mongo` object:\n```javascript\nmongo: {\n  connection // current connection to MongoDB\n}\n```\n\n#### Webserver\nExports express application as `express` and http-server as `http`.  \nTakes Options:\n- **compression** { boolean } if on - express will use compression middleware as the first one. `default: true`\n- **midllewares** { array | object } standard express middlewares list. `default: {}` \n\n#### Session\nExports `session` object: \n```javascript\nsession: {\n  store, \n  key,\n  secret\n}\n```\nTakes options:\n- **store**: session store. `default:` provided by `connect-mongo` and `express-session`\n- **key**: session key. `default: osnova.opts.core.session.key`\n- **secret**: session secret string. `default: osnova.opts.core.session.secret`\n- **connection**: connection to MongoDB. `default: osnova.mongo.connection`\n---\n\nCore modules can be configured in OSNOVA options object `core.modules` branch:\n\n```javascript\nconst osnova = OSNOVA({\n  core: {\n    modules: {\n      webserver: {\n        use: true,\n        compression: false\n      },\n      mongo: {\n        //undefined `use` treats as true\n      },\n      session: false // you can just set `false` to turn off core module      \n    }\n  }\n})\n```\n\n### OSNOVA Options\n- **listen** { function } will be called with `osnova.http` as an argument \nwhen all modules are ready. if `undefined` of `'default'` \nwill be used built-in standard listen.\n\n- **DEBUG** { object } enable debug-messages mode for specific parts of OSNOVA. `default:` everything is off.\n\n### Samples\n \n#### Add routes\nYou **can't** do this: \n\n```javascript\nconst osnova = OSNOVA(opts);\n\nconst express = osnova.express; // app - undefined\nexpress.get('/myroute', (req, res) =\u003e { res.send('hello') });\n\nosnova.start();\n```\n\nThe right way is to call routing from `start` callback or create a module:\n\n```javascript\n\nconst myRouting = osnova =\u003e {\n  const express = osnova.express;\n  express.get('/route1', (req, res) =\u003e { res.send('hello from route1') });\n  express.get('/route2', (req, res) =\u003e { res.send('hello from route2') });\n  osnova.next();\n}\n\nconst osnova = OSNOVA({\n  modules: [ myRouting ],\n  listen: 'default'\n});\n\nosnova.start();\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fosnova","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoviel%2Fosnova","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fosnova/lists"}