Giter Site home page Giter Site logo

alfg / srv Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 0.0 504 KB

▼ A modern, opinionated and simple microservices stack built on Express.

Home Page: https://github.com/alfg/srv

License: MIT License

JavaScript 100.00%
node es6 framework microservices es2015 babel srv

srv's Introduction

▼srv

A modern, opinionated and simple microservices stack built on Express.

npm-version dependencies Build Status Build status Coverage Status Greenkeeper badge

Why?

Creating services using the microservices architecture pattern can involve a lot of repeated boilerplate code including server, logging, documentation, transpilation and other middleware.

srv helps combine the common boilerplate code, while allowing you to extend as needed.

Features

  • Minimal CLI + Framework over Express
  • Babel Transpilation
  • Logging
  • RESTful Documentation Generation
  • CORS
  • Linting (eslint)

Included Modules

  • Express — Minimalist web framework
  • Babel — Javascript Transpilation.
  • Winston Logging — A multi-transport async logging library for node.js.
  • apiDoc — Inline Documentation for RESTful web APIs.
  • ESLint — Linting utility.
  • dotenv — Environment variables.

Install

$ npm install -g srv-cli
$ srv --help

or local (without bin symlink):

$ npm install srv-cli --no-bin-links
$ node node_modules/srv-cli/build/srv --help

Example

Create hello.js with a default export:

export default function hello(app) {
    app.get('/hello', (req, res) => {
        res.send("Hello world!");
    })
}

The 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.

You can run the application directly with srv:

$ srv hello.js

▼ Babel transpiled.
▼ Ready! Listening on: http://0.0.0.0:3000

Any ES2015 code will automatically be transpiled (via babel), then served at the default host + port. See the CLI Reference for more options and features.

CLI Reference

$ srv --help
Usage: srv entrypoint.js [options]

Options:

  -h, --help            output usage information
  -V, --version         output the version number
  -p, --port [n]        Port to listen on
  -H, --host [value]    Host to listen on
  -D, --docs [value]    Generate Docs from folder
  -L, --lint            Lint code with ESLint
  -n, --no-babel        Skip Babel transformation
  -C, --config [value]  Configuration file

Generating Documentation

RESTful documentation generation is based on apiDoc params. See example/hello.js for an example.

Run the following command to generate documentation:

$ srv entrypoint.js --docs examples

examples - Generate Docs from folder.

View docs at: http://0.0.0.0:3000/docs

Refer to http://apidocjs.com/#params for supported apiDoc params.

Babel/ES6

By 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!

See https://babeljs.io/docs/plugins/preset-env/ for supported plugins loaded by preset-env.

You can disable the transpilation by providing the --no-babel flag.

Logging

Winston logging transport is enabled by default and will log all http info logs to logs/ and all console debug logs to stdout.

You can also call the logging instance directly via the express.logger context.

See examples/hello.js for an example.

CORS

CORS middleware is enabled for all requests by default (via express-cors)

You can configure whitelisted domains in the default configuration.

Configuration

Configuration defaults are set on 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.

$ srv examples/hello.js --config custom.json

This will use default.json as a base config and extend using your provided configuration.

Environment Variables

srv uses dotenv to load environment varaibles from a .env file into process.env.

Just 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:

DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3

That's it.

process.env now has the keys and values you defined in your .env file.

db.connect({
  host: process.env.DB_HOST,
  username: process.env.DB_USER,
  password: process.env.DB_PASS
});

This makes it easy for development, but it is not recommended to add your .env files into VCS.

Linting

srv uses ESLint to lint your code using the airbnb-base config.

To eslint your code, just use the --lint flag:

$ srv examples/hello.js --lint

If you wish to update the default profile, you can set lint options on your custom configuration.

  "lint": {
    "rules": {
        "extends": "airbnb-base",
    }
  }

Adding Middleware

Adding extra middleware is easy. Simply export a middleware function in your entrypoint file containing your middleware loaders.

Example:

export function middleware(app) {
  app.use(awesomeMiddleware);
  app.use(anotherMiddleware);
}

See examples/middleware-example.js for an example.

Contributing

See: CONTRIBUTING.md

Change Log

See: CHANGELOG.md

License

See: LICENSE

srv's People

Contributors

alfg avatar greenkeeper[bot] avatar sirlancelot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

srv's Issues

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of apidoc is breaking the build 🚨

The dependency apidoc was updated from 0.17.6 to 0.17.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

apidoc is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • coverage/coveralls: First build on greenkeeper/apidoc-0.17.7 at 91.892% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 13 commits.

  • 16bf56a Merge pull request #760 from manishsaraan/publish-with-commander
  • 0e262e6 version bump
  • 8c08b52 Merge pull request #752 from panz3r/nomnom-migration
  • 54d32b1 fix(Test): Fix failing test
  • bd27fa0 feat(Commander): Migrate 'nomnom' to 'commander-js'
  • 4675adb Merge pull request #751 from manishsaraan/update-dependencies
  • 6e86605 winston logger code updated
  • faad2d3 Merge pull request #729 from misaon/patch-2
  • b4ec4b8 Merge pull request #728 from misaon/patch-1
  • d8916c1 dependencies updated
  • 9f44fc6 enable Czech translation (PR: #728)
  • 4fcae49 Update cs.js
  • d43a2f6 Add Czech translation.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel-eslint is breaking the build 🚨

Version 8.0.3 of babel-eslint was just published.

Branch Build failing 🚨
Dependency babel-eslint
Current Version 8.0.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

babel-eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build passed Details
  • coverage/coveralls First build on greenkeeper/babel-eslint-8.0.3 at 90.0% Details
  • continuous-integration/appveyor/branch AppVeyor build failed Details

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of gulp-eslint is breaking the build 🚨

Version 4.0.1 of gulp-eslint was just published.

Branch Build failing 🚨
Dependency gulp-eslint
Current Version 4.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

gulp-eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • coverage/coveralls Coverage pending from Coveralls.io Details
  • continuous-integration/appveyor/branch AppVeyor build succeeded Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 6 commits.

  • 1d79ed0 4.0.1
  • 8f7e966 replace all HTTP protocols with HTTPS
  • b48a04a remove deprecated gulp-util dependency (#213)
  • 35eae57 update devDependencies (#207)
  • 47bd269 use npx to simplify after_script
  • 29dbab5 inherit autofix-related props even if quiet option is enabled

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of commander is breaking the build 🚨

Version 2.18.0 of commander was just published.

Branch Build failing 🚨
Dependency commander
Current Version 2.17.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

commander is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • coverage/coveralls: First build on greenkeeper/commander-2.18.0 at 91.892% (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Release Notes v2.18.0
  • Standardize help output (#853)
  • chmod 644 travis.yml (#851)
  • add support for execute typescript subcommand via ts-node (#849)
Commits

The new version differs by 5 commits.

  • 54b7f14 version bump 2.18.0
  • 713db77 Standardize help output (#853)
  • af17996 chmod 644 travis.yml
  • 8bcc493 Merge pull request #849 from KillWolfVlad/feature/executeSubCommand-tsnode
  • bf47dcc add support for execute typescript subcommand via ts-node

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.