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.

157 lines
3.2 KiB

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