-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from KunalKapadia/develop-yarn
Replace npm with yarn
- Loading branch information
Showing
4 changed files
with
4,868 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,13 @@ Heavily inspired from [Egghead.io - How to Write an Open Source JavaScript Libra | |
| Authentication via JsonWebToken | Supports authentication using [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken). | | ||
| Code Linting | JavaScript code linting is done using [ESLint](http://eslint.org) - a pluggable linter tool for identifying and reporting on patterns in JavaScript. Uses ESLint with [eslint-config-airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb), which tries to follow the Airbnb JavaScript style guide. | | ||
| Auto server restart | Restart the server using [nodemon](https://github.com/remy/nodemon) in real-time anytime an edit is made, with babel compilation and eslint. | | ||
| ES6 Code Coverage via [istanbul](https://www.npmjs.com/package/istanbul) | Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in `coverage/` directory post `npm test` execution. Open `coverage/lcov-report/index.html` to view coverage report. `npm test` also displays code coverage summary on console. Code coverage can also be enforced overall and per file as well, configured via .istanbul.yml | | ||
| ES6 Code Coverage via [istanbul](https://www.npmjs.com/package/istanbul) | Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in `coverage/` directory post `yarn test` execution. Open `coverage/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 via [debug](https://www.npmjs.com/package/debug) | Instead 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 via [bluebird](https://github.com/petkaantonov/bluebird) | We love promise, don't we ? All our code is promisified and even so our tests via [supertest-as-promised](https://www.npmjs.com/package/supertest-as-promised). | | ||
| API parameter validation via [express-validation](https://www.npmjs.com/package/express-validation) | Validate 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 hooks | Runs lint and tests before any commit is made locally, making sure that only tested and quality code is committed | ||
| Secure app via [helmet](https://github.com/helmetjs/helmet) | Helmet helps secure Express apps by setting various HTTP headers. | | ||
| Uses [yarn](https://yarnpkg.com) over npm | Uses new released yarn package manager by facebook. You can read more about it [here](https://code.facebook.com/posts/1840075619545360) | | ||
|
||
- CORS support via [cors](https://github.com/expressjs/cors) | ||
- Uses [http-status](https://www.npmjs.com/package/http-status) to set http status code. It is recommended to use `httpStatus.INTERNAL_SERVER_ERROR` instead of directly using `500` when setting status code. | ||
|
@@ -44,41 +45,46 @@ git clone [email protected]:KunalKapadia/express-mongoose-es6-rest-api.git | |
cd express-mongoose-es6-rest-api | ||
``` | ||
|
||
Install yarn: | ||
```js | ||
npm install -g yarn | ||
``` | ||
|
||
Install dependencies: | ||
```sh | ||
npm install | ||
yarn | ||
``` | ||
|
||
Start server: | ||
```sh | ||
# Start server | ||
npm start | ||
yarn start | ||
|
||
# Selectively set DEBUG env var to get logs | ||
DEBUG=express-mongoose-es6-rest-api:* npm start | ||
DEBUG=express-mongoose-es6-rest-api:* yarn start | ||
``` | ||
Refer [debug](https://www.npmjs.com/package/debug) to know how to selectively turn on logs. | ||
|
||
|
||
Tests: | ||
```sh | ||
# Run tests written in ES6 along with code coverage | ||
npm test | ||
yarn test | ||
|
||
# Run tests on file change | ||
npm run test:watch | ||
yarn test:watch | ||
|
||
# Run tests enforcing code coverage (configured via .istanbul.yml) | ||
npm run test:check-coverage | ||
yarn test:check-coverage | ||
``` | ||
|
||
Lint: | ||
```sh | ||
# Lint code with ESLint | ||
npm run lint | ||
yarn lint | ||
|
||
# Run lint on any file change | ||
npm run lint:watch | ||
yarn lint:watch | ||
``` | ||
|
||
Other gulp tasks: | ||
|
@@ -94,13 +100,13 @@ gulp | |
|
||
```sh | ||
# compile to ES5 | ||
1. npm run build | ||
1. yarn build | ||
|
||
# upload dist/ to your server | ||
2. scp -rp dist/ user@dest:/path | ||
|
||
# install production dependencies only | ||
3. npm i --production | ||
3. yarn --production | ||
|
||
# Use any process manager to start your services | ||
4. pm2 start dist/index.js | ||
|
@@ -122,10 +128,10 @@ Logs stacktrace of error to console along with other details. You should ideally | |
![Error logging](https://cloud.githubusercontent.com/assets/4172932/12563361/fb9ef108-c3cf-11e5-9a58-3c5c4936ae3e.JPG) | ||
|
||
## Code Coverage | ||
Get code coverage summary on executing `npm test` | ||
Get code coverage summary on executing `yarn test` | ||
![Code Coverage Text Summary](https://cloud.githubusercontent.com/assets/4172932/12827832/a0531e70-cba7-11e5-9b7c-9e7f833d8f9f.JPG) | ||
|
||
`npm test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it. | ||
`yarn test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it. | ||
![Code coverage HTML report](https://cloud.githubusercontent.com/assets/4172932/12625331/571a48fe-c559-11e5-8aa0-f9aacfb8c1cb.jpg) | ||
|
||
## A Boilerplate-only Option | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.