A RESTful API generated by apidoc.
See the API's documentation
Create a .env
file in the root directory of your project. Add
environment-specific variables on new lines in the form of NAME=VALUE
.
For example:
APP_ENV=
APP_DEBUG=
DB_MONGO_URI=
DB_MONGO_DATABASENAME=
HTTP_SERVER_PORT=8000
HTTP_SERVER_API_ROOT=/
process.env
now has the keys and values you defined in your .env
file.
Add some apidoc comments anywhere in your source code:
/**
* @api {post} /records Query on record
* @apiName Query
* @apiGroup Record
* @apiParam startDate Minimum value (inclusive) for 'createdAt' field of Record
* @apiParam endDate Maximum value (exclusive) for 'createdAt' field of Record
* @apiParam minCount Minimum value (inclusive) for sum of 'counts' field of Record
* @apiParam maxCount Maximum value (exclusive) for sum of 'counts' field of Record
* @apiSuccess {Object} records Record's data.
* @apiSuccess {Object} msg Conditional message
* @apiSuccess {String} msg Conditional message
* @apiError {Number} code 3 Some parameters may contain invalid values.
*/
Now generate the documentation from src/
into docs/
.
$ npm run apidoc
After you generate your project, these commands are available in package.json
.
npm test # test using Jest
npm run lint # lint using ESLint
npm run dev # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs
Here is where the API endpoints are defined. Each API has its own folder.
It defines the Mongoose schema and model for the Records API endpoint. Any changes to the data model should be done here.
This is the Records API controller file. It defines the main router middlewares which use the API model.
This is the entry file of the Records API.
Here you can find web servers
and other types of modules which I use in my APIs.
Here you can find helpers
Testing NodeJs/Express API with Jest and Supertest
npm test