Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

💥 A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication

License

NotificationsYou must be signed in to change notification settings

cwgabel/express-mongoose-es6-rest-api

 
 

Repository files navigation

Build StatusCoverage StatusCode ClimatebitHound Overall ScorebitHound DependenciesCommitizen friendlyMIT LicensePRs WelcomeSupport via Paypal

Code Sponsor

Express ES6 REST API Starter

Overview

This is a boilerplate application for building REST APIs in Node.js using ES6 and Express with Code Coverage and JWT Authentication. Helps you stay productive by following best practices. FollowsAirbnb's Javascript style guide.

Heavily inspired fromEgghead.io - How to Write an Open Source JavaScript Library.

Features

FeatureSummary
ES6 via BabelES6 support usingBabel.
Authentication via JsonWebTokenSupports authentication usingjsonwebtoken.
Code LintingJavaScript code linting is done usingESLint - a pluggable linter tool for identifying and reporting on patterns in JavaScript. Uses ESLint witheslint-config-airbnb, which tries to follow the Airbnb JavaScript style guide.
Auto server restartRestart the server usingnodemon in real-time anytime an edit is made, with babel compilation and eslint.
ES6 Code Coverage viaistanbulSupports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved incoverage/ directory postyarn test execution. Opencoverage/lcov-report/index.html to view coverage report.yarn test also displays code coverage summary on console. Code coverage can also be enforced overall and per file as well, configured via .istanbul.yml
Debugging viadebugInstead of inserting and deleting console.log you can replace it with the debug function and just leave it there. You can then selectively debug portions of your code by setting DEBUG env variable. If DEBUG env variable is not set, nothing is displayed to the console.
Promisified Code viabluebirdWe love promise, don't we ? All our code is promisified and even so our tests viasupertest-as-promised.
API parameter validation viaexpress-validationValidate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail. You won't anymore need to make your route handler dirty with such validations.
Pre-commit hooksRuns lint and tests before any commit is made locally, making sure that only tested and quality code is committed
Secure app viahelmetHelmet helps secure Express apps by setting various HTTP headers.
Usesyarn over npmUses new released yarn package manager by facebook. You can read more about ithere
  • CORS support viacors
  • Useshttp-status to set http status code. It is recommended to usehttpStatus.INTERNAL_SERVER_ERROR instead of directly using500 when setting status code.
  • Has.editorconfig which helps developers define and maintain consistent coding styles between different editors and IDEs.

Getting Started

Clone the repo:

git clone git@github.com:kunalkapadia/express-mongoose-es6-rest-api.gitcd express-mongoose-es6-rest-api

Install yarn:

npminstall-gyarn

Install dependencies:

yarn

Set environment (vars):

cp .env.example .env

Start server:

# Start serveryarn start# Selectively set DEBUG env var to get logsDEBUG=express-mongoose-es6-rest-api:* yarn start

Referdebug to know how to selectively turn on logs.

Tests:

# Run tests written in ES6yarntest# Run test along with code coverageyarn test:coverage# Run tests on file changeyarn test:watch# Run tests enforcing code coverage (configured via .istanbul.yml)yarn test:check-coverage

Lint:

# Lint code with ESLintyarn lint# Run lint on any file changeyarn lint:watch

Other gulp tasks:

# Wipe out dist and coverage directorygulp clean# Default task: Wipes out dist and coverage directory. Compiles using babel.gulp
Deployment
# compile to ES51. yarn build# upload dist/ to your server2. scp -rp dist/ user@dest:/path# install production dependencies only3. yarn --production# Use any process manager to start your services4. pm2 start dist/index.js

In production you need to make sure your server is always up so you should ideally use any of the process manager recommendedhere.We recommendpm2 as it has several useful features like it can be configured to auto-start your services if system is rebooted.

Logging

Universal logging librarywinston is used for logging. It has support for multiple transports. A transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels. For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file. We just log to the console for simplicity, you can configure more transports as per your requirement.

API logging

Logs detailed info about each api request to console during development.Detailed API logging

Error logging

Logs stacktrace of error to console along with other details. You should ideally store all error messages persistently.Error logging

Code Coverage

Get code coverage summary on executingyarn testCode Coverage Text Summary

yarn test also generates HTML code coverage report incoverage/ directory. Openlcov-report/index.html to view it.Code coverage HTML report

Docker

Using Docker Compose for Development

# service restarts on file changebash bin/development.sh

Building and running without Docker Compose

# To use this option you need to make sure mongodb is listening on port 27017# Build dockerdocker build -t express-mongoose-es6-rest-api.# Run dockerdocker run -p 4040:4040 express-mongoose-es6-rest-api

A Boilerplate-only Option

If you would prefer not to use any of our tooling, delete the following files from the project:package.json,gulpfile.babel.js,.eslintrc and.travis.yml. You can now safely use the boilerplate with an alternative build-system or no build-system at all if you choose.

Docs and Recipes

  • Gulp recipes - the official Gulp recipes directory includes a comprehensive list of guides for different workflows you can add to your project.

Contributing

Contributions, questions and comments are all welcome and encouraged. For code contributions submit a pull request with unit test.

License

This project is licensed under theMIT License

Support Development

If this project saved your valuable time in getting your service up, and you feel like buying me coffee, you can donate either at my BTC address:1LkW5UoERR1jjJsChMheKuo6vn95x2mzWg or atSupport via Paypal

Your support is greatly appreciated.

Meta

Kunal Kapadia –@kunalkapadia12kunalkapadia12@gmail.com

About

💥 A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript95.1%
  • Dockerfile2.7%
  • Shell2.2%

[8]ページ先頭

©2009-2025 Movatter.jp