项目作者: firmanJS

项目描述 :
template for develop api in expressjs
高级语言: JavaScript
项目地址: git://github.com/firmanJS/express-template.git
创建时间: 2021-05-19T06:15:57Z
项目社区:https://github.com/firmanJS/express-template

开源协议:MIT License

下载


Express Template Boillerplate RestfullApi

Maintainability
Test Coverage
Node.js CI
made-with-nodejs
made-with-expressjs
Ask Me Anything !
GitHub license
GitHub release
Github all releases
GitHub issues
GitHub pull-requests
PRs Welcome

How To use

you must click the button use this template

  • using template - create name of your repository
  • rename link readme - change link repo default github/firmanJS/express-template to your repo
  • codeclimate - you must integrate repo to codeclimate don’t forget set your repo is public for integrated and in github repo settings create secret key with name CC_TEST_REPORTER_ID and value from code climate REPORTER ID in https://codeclimate.com/

or clone this repository via https :

  1. https://github.com/firmanJS/express-template.git

default branch using commonjs if you want version ecmascript you must checkout to branch version/ecmascript

Core Stack

Feature

  1. error handling
  2. database structure folder
  3. testing with jest
  4. coverage use jest
  5. with docker example
  6. validiation, use express-valdator and joi
  7. pagination example
  8. custom message api response
  9. eslint airbnb base

Unit testing

How To run

copy environment variable

  1. cp .env-sample .env

run manualy

  • via yarn or npm :
  1. # install package
  2. npm install or yarn install
  3. # running app
  4. npm run dev or yarn dev
  5. # running unit tetsing
  6. npm run test or yarn test
  • via make :
  1. # start aplication with docker
  2. make docker-start
  3. # stop docker container
  4. make docker-stop
  5. # remove docker container
  6. make docker-down

fill in the copied environment earlier

  1. PORT=2000
  2. TZ=Asia/Jakarta
  3. MONGO_SERVICE=# uri mongodb
  4. AUTH_SOURCE= #auth service
  5. SECRET_KEY= #jwt secret key here

run with docker-compose

  1. docker-compose up --build

or run with background process

  1. docker-compose up --build -d

execution npm with container docker

  1. # install package
  2. docker-compose exec boillerplate npm install
  3. # running unit testing
  4. docker-compose exec boillerplate npm run test

Documentation API

using swagger check in folder static

Project Structure

  1. .
  2. ├── .github/ * all workflows github actions
  3. ├── caprover/ * for deployment in caprover
  4. ├── coverage/ * all output coverage
  5. ├── docker/ * all dockerfile
  6. ├── src/ * all source code in here
  7. └── config/ * all configuration file here
  8. | └── db.js * configuration database
  9. └── database/ * all models schema file here
  10. | └── models * all models file
  11. | └── migrations * all migrations file
  12. | └── seeders * all seeders file
  13. └── handlers/ * all file handlers here
  14. | └── index.js * register all handler here
  15. └── lang/ * setup language
  16. | └── index.js * register all language here
  17. └── middleware/ * all middleware file here, for check before next to api
  18. └── repository/ * all file repository for single db or multiple db
  19. | └── monggo * register all monggo
  20. | └── mysql * register all mysql
  21. | └── postgresql * register all postgresql
  22. └── routes/ * all file route here
  23. | └── index.js * register all route
  24. └── static/ * config for swagger
  25. | └── swagger.json * config swagger
  26. └── test/ * all test file here
  27. | └── index.js * test apps
  28. └── utils/ * all utils file here

Code Style Guides

  • Guideline:
    • Use camelCase for variable name, naming function, load module or other functions
    • Use UpperCase for Constant Variable
    • Use PascalCase for class name, models
    • Use snake_case for file name as variable
    • Function name use Verb
    • Variable name use Noun