Skip to content

metehanakbaba/getir-nodejs-challenge

Repository files navigation

JavaScript TravisCI NodeJS MongoDB NPM GitHub AWS Jest

Build Status Code Average JavaScript Style Guide: Airbnb Node Version NPM Version


Getir NodeJS Challenge

A RESTful API generated by apidoc.

See the API's documentation

Usage

Environments


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.

Api Documentation


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

Execute Commands

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

Directory structure

src/route/

Here is where the API endpoints are defined. Each API has its own folder.

src/route/record/model.js

It defines the Mongoose schema and model for the Records API endpoint. Any changes to the data model should be done here.

src/route/record/controller.js

This is the Records API controller file. It defines the main router middlewares which use the API model.

src/route/record/index.js

This is the entry file of the Records API.

services/

Here you can find web servers and other types of modules which I use in my APIs.

utils/

Here you can find helpers

test/

Testing NodeJs/Express API with Jest and Supertest

npm test