Fully featured Koa.JS restful api starter application. The goal of this project is to solve all routine tasks and keep your focus on the product and business logic of the application, not on the common things, such logging, configuration, dev/production environments
Out of the box support following features:
- Config management.
- Configured console logger based on common-logger.
- Automatic application restart when code changes with Nodemon.
- MongoDB configuration.
- Docker configuration for development and production environments.
- Code linting based on @auxilin/eslint-config.
- Simplified request data validation and clean up based on joi.
- Production ready account API resource (singup, signin, forgot password, reset password functionality).
- JWT based authentication.
- Tests for endpoints.
In order to start server in the docker container you can use bash file ./bin/start.sh
:
$ ./bin/start.sh
To start the project not in the docker container just run: npm run development
. This command will start the application on port 3001
and will automatically restart whenever you change any file in ./src
directory.
We try to keep things as simple as possible, so you can focus on building product instead of learning concepts.
There are two main directories within project:
-
src/config - consist of configuration for the environment, koa server and API routes.
-
src/config/routes - consist of public (don't require jwt token) and authenticated (require jwt token) routes and middlewares.
- middlewares - koa middlewares which we use on every request (for example, get current user data from the database)
-
src/resources - REST api resources and everything related to the resource:
- database service - resource service to work with database (MongoDB or other database)
- database schema - database schema for the resource entity.
- validators - request validation logic. You can use this validators inside of the validation middleware (example in ./src/resources/account/public.js) or you can use this validators inside of the controller (example in ./src/resources/user/user.controller.js)
- controllers - the central place for the request handling and data manipulation.
- builders - creating database documents for testing.
- factory - predefined types of database documents for testing.
- tests - mocha tests for the endpoint.
-
src/services - application services for various purposes. Not this directory contains the following services:
- src/services/auth.service.js - JWT based authentication helper. Consist logic of JWT token encryption/decryption. Can consist other authentication related functions.
- src/services/email.service.js - fake service for sending application emails.
- src/services/cache.service.js - service for work with application cache.
All other files, that does not fit that structure should be placed straight in the src
folder. We can always introduce more folders as we need them. Currently root folder consist following:
- src/app.constants.js - constant variables that are used in the application.
- src/app.js - starting point of the node.js application. It combine application configuration and start Koa http listener.
- src/db.js - handles connection to the MongoDB.
- src/logger.js - application logger.
- src/security.util.js - number of methods for generating secure tokens and comparing passwords with password hash.
- Implement email service.
Koa.JS REST api starter is released under the MIT License.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Join us and share something developers need 👌.
Thanks goes to these wonderful people (emoji key):
Evgeny Zhivitsa 💻 📖 🤔 👀 |
Andrew Orsich 📖 🤔 👀 |
This project follows the all-contributors specification. Contributions of any kind welcome!