Chronas API
This API provides authentication and CRUD operations for data used by the Chronas application. It is based on Node.js using ES6 and Express with Code Coverage and JWT Authentication. It implies an underlying MongoDB.
Feature | Summary |
---|---|
ES6 via Babel | ES6 support using Babel. |
Authentication via JsonWebToken | Supports authentication using jsonwebtoken. |
Code Linting | JavaScript code linting is done using ESLint - a pluggable linter tool for identifying and reporting on patterns in JavaScript. Uses ESLint with eslint-config-airbnb, which tries to follow the Airbnb JavaScript style guide. |
Auto server restart | Restart the server using nodemon in real-time anytime an edit is made, with babel compilation and eslint. |
Swagger | Using swagger-ui-express Path to Docu /api-docs |
Postman | Here you can find the Postman Dokumentation and the Postman test collection and environment can be found here |
ES6 Code Coverage via 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 |
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. |
Infrastructure Information | MongoDB Restore in K8s to Azure, Create MongoDB in K8s |
- CORS support via cors
- Uses http-status to set http status code. It is recommended to use
httpStatus.INTERNAL_SERVER_ERROR
instead of directly using500
when setting status code. - Has
.editorconfig
which helps developers define and maintain consistent coding styles between different editors and IDEs.
Clone the repo:
git clone https://github.com/Chronasorg/chronas-api
Install dependencies:
cd chronas-api
npm i
Set environment (vars):
cp .env.example .env
Start an local mongoDB instance e.g. with an docker container:
docker run -d --name mongodatabase -p27017:27017 mongo
Start:
npm start
# Selectively set DEBUG env var to get logs
DEBUG=chronas-api:* npm start
Refer debug to know how to selectively turn on logs.
Tests:
# Run tests written in ES6
npm test
# Run test along with code coverage
npm run test:coverage
# Run tests on file change
npm run test:watch
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 install --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.
Logs detailed info about each api request to console during development.
Logs stacktrace of error to console along with other details.
The Dockerfile contains a multistage build. It installs node models and builds the application on a base node image and copy it to an node-alphine image.
To run the application use docker-compose as it will start also a mongodb:
docker-compose up
If you want to run it without docker-compose use this commands:
docker run -d -p27017:27017 --name mongodatabase mongo
docker build -t chronas-api-local . && docker run -it --link mongodatabase:mongodatabase -e MONGO_HOST='MONGO_HOST=mongodb://mongodatabase/chronas-api' --name chrona-api -p 80:80 chronas-api-local
chronas-api's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.