This is the server for our android application Swiplist. It is based on Express & mongoose REST API Boilerplate in ES6 with Code Coverage, which includes some starter build config and project structure to enable us to quickly start implementing our project specific features. All the main features are implemented by ourselves.
Some of the implemented APIs
- Authentication, such as login and register
- CRUD for users and items
- Data import from Steam and MyAnimeList, which import the game library list, anime list and manga list
- Items suggestion API for each users
- Friends suggestion API for each users
Clone the repo:
git clone https://github.com/Swiplist/Swiplist-Server.git cd Swiplist-Server
npm install -g yarn
Set environment (vars):
cp .env.example .env
Notice that you will need to fill in the blank after
STEAM_WEB_API_KEY= with your own steam web api key.
Install and start MongoDB server before starting this node.js server:
# Start server mongod
# Start server yarn start # Selectively set DEBUG env var to get logs DEBUG=express-mongoose-es6-rest-api:* yarn start
Refer debug to know how to selectively turn on logs.
# Run tests written in ES6 yarn test # Run test along with code coverage yarn test:coverage # Run tests on file change yarn test:watch # Run tests enforcing code coverage (configured via .istanbul.yml) yarn test:check-coverage
# Lint code with ESLint yarn lint # Run lint on any file change yarn 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. yarn build # upload dist/ to your server 2. scp -rp dist/ user@dest:/path # install production dependencies only 3. yarn --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.
Universal logging library winston is used for logging. It has support for multiple transports. A transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels. For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file. We just log to the console for simplicity, you can configure more transports as per your requirement.
Using Docker Compose for Development
# service restarts on file change bash bin/development.sh
Building and running without Docker Compose
# To use this option you need to make sure mongodb is listening on port 27017 # Build docker docker build -t express-mongoose-es6-rest-api . # Run docker docker run -p 4040:4040 express-mongoose-es6-rest-api
This project is licensed under the Apache License 2.0
|ES6 via Babel||ES6 support using Babel.|
|Authentication via JsonWebToken||Supports authentication using jsonwebtoken.|
|Auto server restart||Restart the server using nodemon in real-time anytime an edit is made, with babel compilation and eslint.|
|ES6 Code Coverage via istanbul||Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in
|Debugging via 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||We love promise, don't we ? All our code is promisified and even so our tests via supertest-as-promised.|
|API parameter validation via 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||Helmet helps secure Express apps by setting various HTTP headers.|
|Uses yarn over npm||Uses new released yarn package manager by facebook. You can read more about it here|
- CORS support via cors
- Uses http-status to set http status code. It is recommended to use
httpStatus.INTERNAL_SERVER_ERRORinstead of directly using
500when setting status code.
.editorconfigwhich helps developers define and maintain consistent coding styles between different editors and IDEs.
The original boilerplate project is licensed under the MIT License