Basic nodejs api
-
Make sure you have Node version >= 8.9 installed
-
Run the following from the command line
git clone https://github.com/Jaaromy/nodejs-api-basic.git
cd nodejs-api-basic
npm install
npm test
npm start
After starting the application, the API documentation can be found by visiting the following url in a browser window:
http://localhost:3000/v1/api-docs
Each of the API methods can be tested by clicking on the method to expand it and then pressing Try it out
then Execute
.
All methods can of course also be called by making a regular REST call to the appropriate endpoint.
Node.js
Express
LowDB
jsonschema
Jest
Swagger
- Types are completely defined in the database as JSON schema (minus the documentation, of course). Only additional properties need to be added to the database as they are then merged with the base properties during validation.
- Assumed that when new unit types are created, documentation will be updated to reflect the changes (by modifying the swagger.json file).
-
While the documentation and endpoints were created for User and Type CRUD operations, they were not implemented and will return a 501 - Not Implemented response code.
-
Update and Delete operations were not implemented for Unit.
-
Security was ignored for purposes of the demo. Anyone can hit the endpoints and the app will automatically assume you are user id "1".
-
While there are basic unit/integration tests, there is not 100% code coverage.
-
LowDB was used for this demo, but the solution is architected in such a way that a new database can be swapped in simply by creating a new "connector" file and referencing it in db.js. A more robust and scalable database (such as DynamoDB or MongoDB) would be an easy drop in.
-
Security and Authorization need to be implemented.
-
Full unit test coverage.
-
A framework such as
pm2
orforever
should be used so that the application automatically restarts if there are issues. -
Setting up CI/CD and deploying to a cloud service.