Skip to content

Commit fd49c9e

Browse files
authored
Merge pull request #157 from KunalKapadia/develop-yarn
Replace npm with yarn
2 parents 75338b7 + d52d19b commit fd49c9e

File tree

4 files changed

+4868
-23
lines changed

4 files changed

+4868
-23
lines changed

.travis.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ language: node_js
22
node_js:
33
- "4.6"
44
- "6.9"
5-
- "7.0"
5+
- "7.2"
66
services:
77
- mongodb
88
cache:
99
directories:
1010
- node_modules
1111
git:
1212
depth: 3
13-
before_script:
14-
- npm prune
1513
after_script:
16-
- npm run report-coverage
14+
- yarn report-coverage

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ Heavily inspired from [Egghead.io - How to Write an Open Source JavaScript Libra
2525
| Authentication via JsonWebToken | Supports authentication using [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken). |
2626
| 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. |
2727
| 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. |
28-
| 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 |
28+
| 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 |
2929
| 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. |
3030
| 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). |
3131
| 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. |
3232
| Pre-commit hooks | Runs lint and tests before any commit is made locally, making sure that only tested and quality code is committed
3333
| Secure app via [helmet](https://github.com/helmetjs/helmet) | Helmet helps secure Express apps by setting various HTTP headers. |
34+
| 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) |
3435

3536
- CORS support via [cors](https://github.com/expressjs/cors)
3637
- 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
4445
cd express-mongoose-es6-rest-api
4546
```
4647

48+
Install yarn:
49+
```js
50+
npm install -g yarn
51+
```
52+
4753
Install dependencies:
4854
```sh
49-
npm install
55+
yarn
5056
```
5157

5258
Start server:
5359
```sh
5460
# Start server
55-
npm start
61+
yarn start
5662

5763
# Selectively set DEBUG env var to get logs
58-
DEBUG=express-mongoose-es6-rest-api:* npm start
64+
DEBUG=express-mongoose-es6-rest-api:* yarn start
5965
```
6066
Refer [debug](https://www.npmjs.com/package/debug) to know how to selectively turn on logs.
6167

6268

6369
Tests:
6470
```sh
6571
# Run tests written in ES6 along with code coverage
66-
npm test
72+
yarn test
6773

6874
# Run tests on file change
69-
npm run test:watch
75+
yarn test:watch
7076

7177
# Run tests enforcing code coverage (configured via .istanbul.yml)
72-
npm run test:check-coverage
78+
yarn test:check-coverage
7379
```
7480

7581
Lint:
7682
```sh
7783
# Lint code with ESLint
78-
npm run lint
84+
yarn lint
7985

8086
# Run lint on any file change
81-
npm run lint:watch
87+
yarn lint:watch
8288
```
8389

8490
Other gulp tasks:
@@ -94,13 +100,13 @@ gulp
94100

95101
```sh
96102
# compile to ES5
97-
1. npm run build
103+
1. yarn build
98104

99105
# upload dist/ to your server
100106
2. scp -rp dist/ user@dest:/path
101107

102108
# install production dependencies only
103-
3. npm i --production
109+
3. yarn --production
104110

105111
# Use any process manager to start your services
106112
4. pm2 start dist/index.js
@@ -122,10 +128,10 @@ Logs stacktrace of error to console along with other details. You should ideally
122128
![Error logging](https://cloud.githubusercontent.com/assets/4172932/12563361/fb9ef108-c3cf-11e5-9a58-3c5c4936ae3e.JPG)
123129

124130
## Code Coverage
125-
Get code coverage summary on executing `npm test`
131+
Get code coverage summary on executing `yarn test`
126132
![Code Coverage Text Summary](https://cloud.githubusercontent.com/assets/4172932/12827832/a0531e70-cba7-11e5-9b7c-9e7f833d8f9f.JPG)
127133

128-
`npm test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it.
134+
`yarn test` also generates HTML code coverage report in `coverage/` directory. Open `lcov-report/index.html` to view it.
129135
![Code coverage HTML report](https://cloud.githubusercontent.com/assets/4172932/12625331/571a48fe-c559-11e5-8aa0-f9aacfb8c1cb.jpg)
130136

131137
## A Boilerplate-only Option

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
"main": "index.js",
77
"private": false,
88
"engines": {
9-
"node": ">=4.6.x",
10-
"npm": ">=2.15.x"
9+
"node": ">=4.6.0",
10+
"npm": ">=2.15.9",
11+
"yarn": ">=0.17.9"
1112
},
1213
"scripts": {
1314
"start": "gulp serve",
1415
"build": "gulp",
1516
"lint": "esw *.js server config --color",
16-
"lint:watch": "npm run lint -- --watch",
17+
"lint:watch": "yarn lint -- --watch",
1718
"test": "NODE_ENV=test babel-node node_modules/.bin/isparta cover _mocha -- --ui bdd --reporter spec --colors --compilers js:babel-core/register ./server/**/*.test.js",
18-
"test:watch": "npm run test -- --watch",
19-
"test:check-coverage": "npm run test && istanbul check-coverage",
19+
"test:watch": "yarn test -- --watch",
20+
"test:check-coverage": "yarn test && istanbul check-coverage",
2021
"report-coverage": "coveralls < ./coverage/lcov.info"
2122
},
2223
"repository": {
@@ -89,7 +90,7 @@
8990
"license": "MIT",
9091
"config": {
9192
"ghooks": {
92-
"pre-commit": "npm run lint && npm test"
93+
"pre-commit": "yarn lint && yarn test"
9394
},
9495
"commitizen": {
9596
"path": "./node_modules/cz-conventional-changelog"

0 commit comments

Comments
 (0)