You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
2.9 KiB

3 years ago
3 years ago
3 years ago
  1. # Express ES2017 REST API Boilerplate
  2. Boilerplate/Generator/Starter Project for building RESTful APIs and microservices using Node.js, Express and MongoDB
  3. ## Features
  4. - No transpilers, just vanilla javascript
  5. - ES2017 latest features like Async/Await
  6. - CORS enabled
  7. - Uses [yarn](https://yarnpkg.com)
  8. - Express + MongoDB ([Mongoose](http://mongoosejs.com/))
  9. - Consistent coding styles with [editorconfig](http://editorconfig.org)
  10. - [Docker](https://www.docker.com/) support
  11. - Uses [helmet](https://github.com/helmetjs/helmet) to set some HTTP headers for security
  12. - Load environment variables from .env files with [dotenv](https://github.com/rolodato/dotenv-safe)
  13. - Request validation with [joi](https://github.com/hapijs/joi)
  14. - Gzip compression with [compression](https://github.com/expressjs/compression)
  15. - Linting with [eslint](http://eslint.org)
  16. - Tests with [mocha](https://mochajs.org), [chai](http://chaijs.com) and [sinon](http://sinonjs.org)
  17. - Code coverage with [istanbul](https://istanbul.js.org) and [coveralls](https://coveralls.io)
  18. - Git hooks with [husky](https://github.com/typicode/husky)
  19. - Logging with [morgan](https://github.com/expressjs/morgan)
  20. - Authentication and Authorization with [passport](http://passportjs.org)
  21. - API documentation generation with [apidoc](http://apidocjs.com)
  22. - Continuous integration support with [travisCI](https://travis-ci.org)
  23. - Monitoring with [pm2](https://github.com/Unitech/pm2)
  24. ## Requirements
  25. - [Node v7.6+](https://nodejs.org/en/download/current/) or [Docker](https://www.docker.com/)
  26. - [Yarn](https://yarnpkg.com/en/docs/install)
  27. ## Getting Started
  28. #### Clone the repo and make it yours:
  29. ```bash
  30. git clone --depth 1 https://git.sentientgeeks.us/krish/sg-node-express-rest-api.git
  31. cd sg-node-express-rest-api
  32. rm -rf .git
  33. ```
  34. #### Install dependencies:
  35. ```bash
  36. yarn
  37. ```
  38. #### Set environment variables:
  39. ```bash
  40. cp .env.example .env
  41. ```
  42. ## Running Locally
  43. ```bash
  44. yarn dev
  45. ```
  46. ## Running in Production
  47. ```bash
  48. yarn start
  49. ```
  50. ## Lint
  51. ```bash
  52. # lint code with ESLint
  53. yarn lint
  54. # try to fix ESLint errors
  55. yarn lint:fix
  56. # lint and watch for changes
  57. yarn lint:watch
  58. ```
  59. ## Test
  60. ```bash
  61. # run all tests with Mocha
  62. yarn test
  63. # run unit tests
  64. yarn test:unit
  65. # run integration tests
  66. yarn test:integration
  67. # run all tests and watch for changes
  68. yarn test:watch
  69. # open nyc test coverage reports
  70. yarn coverage
  71. ```
  72. ## Validate
  73. ```bash
  74. # run lint and tests
  75. yarn validate
  76. ```
  77. ## Logs
  78. ```bash
  79. # show logs in production
  80. pm2 logs
  81. ```
  82. ## Documentation
  83. ```bash
  84. # generate and open api documentation
  85. yarn docs
  86. ```
  87. ## Docker
  88. ```bash
  89. # run container locally
  90. yarn docker:dev
  91. # run container in production
  92. yarn docker:prod
  93. # run tests
  94. yarn docker:test
  95. ```
  96. ## Deploy
  97. Set your server ip:
  98. ```bash
  99. DEPLOY_SERVER=127.0.0.1
  100. ```
  101. Replace my Docker username with yours:
  102. ```bash
  103. nano deploy.sh
  104. ```
  105. Run deploy script:
  106. ```bash
  107. yarn deploy
  108. ```