# npm-run-setups
The primary question is whether `npm start` and `npm test` should be setup for developer convenience and other commands like `npm run heroku` and `npm run travis` should be setup for services. Or should `npm start` and `npm test` should be kept for production and test environments respectively and customer scripts like `npm run dev:start` and `npm run dev:test` should be created for development.
The secondary question is... what should they be named?
Below are examples of the scripts at the various phases of the course
## Basic - Node/Express
This version would be used at the beginning of the course, before testing has been introduced
```json
"scripts": {
"start": "node server.js"
},
```
Introduce this setup during the during express but before mocha
```json
"scripts": {
"start": "node server.js",
"dev:start": "nodemon server.js"
}
```
## Intermediate: Mocha Testing
Introduce this setup for mocha testing
- Keep `npm start` and `npm test` reserved for Heroku and Travis. Create `npm run dev:start` and `npm run dev:test` scripts for development.
```json
"scripts": {
"start": "node server.js",
"test": "cross-env NODE_ENV=test mocha",
"dev:start": "nodemon server.js",
"dev:test": "nodemon --exec npm test"
},
```
The proposed solutions use `process.env.NODE_ENV` to determine the correct database connection and suppress logging. It is considered bad practice to set `process.env.NODE_ENV` in code or use globals like so we'll set it in the command using `cross-env` so it works cross platform. This also assumes the use of a `.env` file and the `dotenv` package for database credentials and jwt secrets.
> Side Note: Never use `mocha --watch`. It may run faster but it causes a the app to create multiple processes and database connections. IMHO, the overhead of adding graceful shutdown scripts for `--watch` (which don't work for SIGINT or SIGTERM) is not worth the effort.
## Advanced: Test Coverage
Propose: Introduce test coverage using `nyc` formerly known as `istanbul` as an advanced/optional lesson.
```json
"scripts": {
"start": "node server.js",
"test": "cross-env NODE_ENV=test mocha",
"dev:start": "nodemon server.js",
"dev:test": "nodemon --exec npm test",
"dev:cover": "nodemon --exec nyc --reporter=lcov --reporter=text-summary npm test"
},
```