This is an example of an API for a book platform implemented with NodeJS and MongoDB.
Main functionalities:
- Register a new user
- Login with a registered user
- Get a list of books
The following packages are required by this package
Package Name | Description |
---|---|
MochaJS | 6.1.4+ |
NodeJS | 10.15.3+ |
Docker | https://www.docker.com/ |
Docker-Compose | https://docs.docker.com/compose/ |
- Clone this repository
- Run
$ cd blog-example-nodejs
(if you used the default project name) - Run
$ cd src
- Copy the .env.example file to a new file called .env with
$ cp .env.example .env
- Configure envinronment variables in
.env
(see env) - Go back to the root directory (
$ cd ../
) and rundocker-compose up
to start the development server
Go to the application
directory using $ cd src
Configure envinronment variables in .env.test
(see env)
Then you can run tests by simply running:
npm run integration-tests
This will run integrations tests (you must have the server up and running)
Environment variable name | Description |
---|---|
APP_NAME | Name of our application |
APP_ENV | Environment name to use |
APP_KEY | base64 key generated |
APP_URL | URL of the application (optional) |
APP_DEBUG | enable debug mode |
DB_HOST | database host |
DB_DATABASE | name of the database to use |
DB_USERNAME | username of the db |
DB_PASSWORD | password for the user |
The following endpoints are available
URL | Description | Authentication |
---|---|---|
GET /books | get a list of public books | required |
POST /users/signin | allows the user to login and obtain a JWT | not required |
POST /users/create | allows the user to signup to the application | not required |
If this was intended to be deployed to production we should:
- Improve the logging solution to keep all the log information centralized and easy to query if needed.
- Improve postman collection to help the frontend and QA to test and use this API.
- Use kubernetes and terraform to deploy.
- Add unit tests for every class and function.
- Improve request validation, separate the entities from the mongoose library. Add a DAO layer to make it easier to switch the database engine.
- Use Redis or another key/value database to manage JWT validation and allow us to invalidate tokens from the server-side.
The Book Example NodeJS is open-sourced software licensed under the MIT license.