This is a boilerplate application for building REST APIs in Node.js using ES6 and Express with Code Coverage and JWT Authentication. Helps you stay productive by following best practices. Follows Airbnb's Javascript style guide.
Clone the repo:
git clone git@github.com:ram-dev/es6restapi.git
cd es6restapi
Install dependencies:
npm install
Start server:
# Start server
npm start
# Selectively set DEBUG env var to get logs
DEBUG=es6-rest-api:* npm start
Refer debug to know how to selectively turn on logs.
Tests:
# Run tests written in ES6 along with code coverage
npm test
# Run tests on file change
npm run test:watch
# Run tests enforcing code coverage (configured via .istanbul.yml)
npm run test:check-coverage
Lint:
# Lint code with ESLint
npm run lint
# Run lint on any file change
npm run lint:watch
Other gulp tasks:
# Wipe out dist and coverage directory
gulp clean
# Default task: Wipes out dist and coverage directory. Compiles using babel.
gulp
# compile to ES5
1. npm run build
# upload dist/ to your server
2. scp -rp dist/ user@dest:/path
# install production dependencies only
3. npm i --production
# Use any process manager to start your services
4. pm2 start dist/index.js
In production you need to make sure your server is always up so you should ideally use any of the process manager recommended here. We recommend pm2 as it has several useful features like it can be configured to auto-start your services if system is rebooted.