{"id":18411388,"url":"https://github.com/alfg/srv","last_synced_at":"2025-04-07T11:31:40.494Z","repository":{"id":37933147,"uuid":"61681954","full_name":"alfg/srv","owner":"alfg","description":"▼ A modern, opinionated and simple microservices stack built on Express.","archived":false,"fork":false,"pushed_at":"2022-06-28T07:00:12.000Z","size":504,"stargazers_count":18,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T16:52:52.625Z","etag":null,"topics":["babel","es2015","es6","framework","microservices","node","srv"],"latest_commit_sha":null,"homepage":"https://github.com/alfg/srv","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/alfg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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-22T02:17:32.000Z","updated_at":"2023-12-19T17:39:03.000Z","dependencies_parsed_at":"2022-09-05T19:20:34.618Z","dependency_job_id":null,"html_url":"https://github.com/alfg/srv","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfg%2Fsrv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfg%2Fsrv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfg%2Fsrv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfg%2Fsrv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alfg","download_url":"https://codeload.github.com/alfg/srv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247644098,"owners_count":20972223,"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":["babel","es2015","es6","framework","microservices","node","srv"],"created_at":"2024-11-06T03:36:42.562Z","updated_at":"2025-04-07T11:31:40.162Z","avatar_url":"https://github.com/alfg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `▼srv`\n\n\u003e A modern, opinionated and simple microservices stack built on Express.\n\n![npm-version](https://img.shields.io/npm/v/srv-cli.svg)\n![dependencies](https://david-dm.org/alfg/srv.svg)\n[![Build Status](https://travis-ci.org/alfg/srv.svg?branch=master)](https://travis-ci.org/alfg/srv)\n[![Build status](https://ci.appveyor.com/api/projects/status/8t5sy362ymvi763j?svg=true)](https://ci.appveyor.com/project/alfg/srv)\n[![Coverage Status](https://coveralls.io/repos/github/alfg/srv/badge.svg?branch=master)](https://coveralls.io/github/alfg/srv?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/alfg/srv.svg)](https://greenkeeper.io/)\n\n## Why?\nCreating services using the [microservices architecture](http://martinfowler.com/articles/microservices.html) pattern can involve a lot of repeated boilerplate code including server, logging, documentation, transpilation and other middleware.\n\n`srv` helps combine the common boilerplate code, while allowing you to extend as needed.\n\n## Features\n* Minimal CLI + Framework over Express\n* Babel Transpilation\n* Logging\n* RESTful Documentation Generation\n* CORS\n* Linting (eslint)\n\n## Included Modules\n* [Express](http://expressjs.com/) \u0026mdash; Minimalist web framework\n* [Babel](https://babeljs.io/) \u0026mdash; Javascript Transpilation.\n* [Winston Logging](https://github.com/winstonjs/winston) \u0026mdash; A multi-transport async logging library for node.js.\n* [apiDoc](http://apidocjs.com) \u0026mdash; Inline Documentation for RESTful web APIs.\n* [ESLint](http://eslint.org/) \u0026mdash; Linting utility.\n* [dotenv](https://github.com/motdotla/dotenv) \u0026mdash; Environment variables.\n\n## Install\n```\n$ npm install -g srv-cli\n$ srv --help\n```\n\nor local (without bin symlink):\n```\n$ npm install srv-cli --no-bin-links\n$ node node_modules/srv-cli/build/srv --help\n```\n\n## Example\nCreate `hello.js` with a default export:\n```javascript\nexport default function hello(app) {\n    app.get('/hello', (req, res) =\u003e {\n        res.send(\"Hello world!\");\n    })\n}\n```\nThe `express` context will be passed into the default export, giving you full access to the express API. No need to write any express boilerplate code.\n\nYou can run the application directly with `srv`:\n```\n$ srv hello.js\n\n▼ Babel transpiled.\n▼ Ready! Listening on: http://0.0.0.0:3000\n```\n\nAny ES2015 code will automatically be transpiled (via babel), then served at the default host + port. See the CLI Reference for more options and features.\n\n## CLI Reference\n```\n$ srv --help\nUsage: srv entrypoint.js [options]\n\nOptions:\n\n  -h, --help            output usage information\n  -V, --version         output the version number\n  -p, --port [n]        Port to listen on\n  -H, --host [value]    Host to listen on\n  -D, --docs [value]    Generate Docs from folder\n  -L, --lint            Lint code with ESLint\n  -n, --no-babel        Skip Babel transformation\n  -C, --config [value]  Configuration file\n```\n\n### Generating Documentation\nRESTful documentation generation is based on [apiDoc](http://apidocjs.com/) params. See [example/hello.js](examples/hello.js) for an example.\n\nRun the following command to generate documentation:\n```\n$ srv entrypoint.js --docs examples\n```\n\n`examples` - Generate Docs from folder.\n\nView docs at: http://0.0.0.0:3000/docs\n\nRefer to http://apidocjs.com/#params for supported apiDoc params.\n\n\n### Babel/ES6\nBy default, `srv` will transpile the entrypoint file (via babel) its dependencies with the preset-env preset. No need to setup babel yourself, it works out of the box!\n\nSee https://babeljs.io/docs/plugins/preset-env/ for supported plugins loaded by preset-env.\n\nYou can disable the transpilation by providing the `--no-babel` flag.\n\n\n## Logging\n[Winston](https://github.com/winstonjs/winston) logging transport is enabled by default and will log all http `info` logs to `logs/` and all console `debug` logs to stdout.\n\nYou can also call the logging instance directly via the `express.logger` context.\n\nSee [examples/hello.js](examples/hello.js) for an example.\n\n\n## CORS\n[CORS](http://enable-cors.org/) middleware is enabled for all requests by default (via [express-cors](https://github.com/expressjs/cors))\n\nYou can configure whitelisted domains in the default configuration.\n\n## Configuration\nConfiguration defaults are set on [default.json](default.json). You can add, extend or override these defaults by creating your own configuration file (as json) and use the `--config` flag when running `srv`.\n\n```\n$ srv examples/hello.js --config custom.json\n```\n\nThis will use `default.json` as a base config and extend using your provided configuration.\n\n## Environment Variables\nsrv uses [dotenv](https://github.com/motdotla/dotenv) to load environment varaibles from a `.env` file into `process.env`.\n\nJust create a `.env` file in the root directory of your project. Add environment-specific variables on new lines in the form of `NAME=VALUE`. For example:\n\n```\nDB_HOST=localhost\nDB_USER=root\nDB_PASS=s1mpl3\n```\n\nThat's it.\n\n`process.env` now has the keys and values you defined in your `.env` file.\n\n```javascript\ndb.connect({\n  host: process.env.DB_HOST,\n  username: process.env.DB_USER,\n  password: process.env.DB_PASS\n});\n```\n\nThis makes it easy for development, but it is not recommended to add your `.env` files into VCS.\n\n## Linting\nsrv uses [ESLint](http://eslint.org) to lint your code using the `airbnb-base` config.\n\nTo eslint your code, just use the `--lint` flag:\n```\n$ srv examples/hello.js --lint\n```\n\nIf you wish to update the default profile, you can set  `lint` options on your custom configuration.\n\n```javascript\n  \"lint\": {\n    \"rules\": {\n        \"extends\": \"airbnb-base\",\n    }\n  }\n```\n\n## Adding Middleware\nAdding extra middleware is easy. Simply export a middleware function in your entrypoint file containing your middleware loaders.\n\nExample:\n```\nexport function middleware(app) {\n  app.use(awesomeMiddleware);\n  app.use(anotherMiddleware);\n}\n```\n\nSee [examples/middleware-example.js](examples/middleware-example.js) for an example.\n\n## Contributing\nSee: [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## Change Log\nSee: [CHANGELOG.md](CHANGELOG.md)\n\n## License\nSee: [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfg%2Fsrv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfg%2Fsrv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfg%2Fsrv/lists"}